Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change default TypeScript behavior to strict: true (fix #41) #103

Merged
merged 1 commit into from
May 16, 2022

Conversation

edemaine
Copy link
Contributor

@edemaine edemaine commented May 8, 2022

This PR enables strict: true diagnostic errors from TypeScript (only when the "Display Errors" checkbox is checked), as requested in #41. Example:

image

But I'm having some trouble with this turned on and the variable actually gets used (so it doesn't get tree shaken away). It seems that TypeScript is somehow processing the same file twice, which leads to new errors:

image

It seems that src/components/editor/monacoTabs.tsx's MonacoTabs creates two models: the model at the top of the function and the model for each tab in tabs. I'm seeing the same source code in both the root model and a tab, which is presumably the source of the problem. Why this isn't a problem without strict mode, I'm not sure. @amoutonbrady Could you explain what's going on here? Could we remove one of the duplicates (presumably the top-level model?)?

@milomg
Copy link
Member

milomg commented May 9, 2022

This is an issue with files that don't have imports or exports and are then treated as a global script file. One trick might be to add a tsconfig flag to ignore output_dont_import.tsx?

@edemaine
Copy link
Contributor Author

@modderme123 Thanks for the tips! I didn't realize it was the lack of import/export that was causing the problem, and that it's an existing issue with the playground. I'll move this to a separate issue (#104).

This PR is now ready for review.

@edemaine edemaine marked this pull request as ready for review May 10, 2022 13:52
@edemaine
Copy link
Contributor Author

Here's yet another example of confusion that this PR will fix: solidjs/solid#972

@amoutonbrady amoutonbrady merged commit f6d99de into solidjs:master May 16, 2022
@amoutonbrady
Copy link
Member

Thanks!

@amoutonbrady
Copy link
Member

Looks like this has one side effect, the default example shows an error :/
image

@edemaine
Copy link
Contributor Author

Looks like this has one side effect, the default example shows an error :/

Ha, whoops; sorry I didn't notice that. It's a useful error message though: document.getElementById can be null which would cause a crash.

One natural way to write this line in TypeScript is this:

render(() => <Counter />, document.getElementById("app")!);

But maybe we want to avoid TypeScript-specific notation in our opening example -- that seems like a nice property to maintain. So then I'd suggest:

const app = document.getElementById("app");
if (app) render(() => <Counter />, app);

It's a little wordier, but is definitely safer. What do you think?

@milomg
Copy link
Member

milomg commented May 17, 2022

Oops, I pushed a commit before I saw this opting for the first one. I'll deploy in a minute

@edemaine
Copy link
Contributor Author

No worries! ! is a good choice too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants