chore: Use moduleDetection
set to force in create-next-app TS templates
#50693
+4
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For Contributors
What?
Up to Typescript 4.9.5, having a module with no imports/exports was labelled as an error. Because of the
isolatedModules
flag being set to true.
However, as of 5.x.x, this has changed, and how TypeScript detects modules is not the same anymore.
I came into contact with this behaviour change in: #50684, I've expanded a bit more in that discussion.
Why?
In TS 5.x.x a file like this:
Makes it so that we can access
Foo
anywhere. Unless we opt-in this file into module land (with animport
orexport
expression/statement).This was not possible up to 4.9.5, where it'd fail with error:
How?
This PR proposes introducing
"moduleDetection": "force",
, to opt-in files as modules, in projects made with create-next-app.This is not final of course. There's a reason why the TS has introduced this change:
Perhaps we should include
"moduleDetection": "auto",
instead, which is the default, and append a section to the README, saying that to avoid the issue described above, one has to change that "force".One has to also wonder if there's actually any potential "danger" of types becoming globally available like that.
I tried to include everything I've been able to gather with respect to this "change in behaviour".
Please feel free to dismiss and close the PR unilaterally if you think it is a non-issue.