Always treat .d.*.ts
files as commonjs-format modules for the purposes of import interop
#59622
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.
Fixes #57229
The way
allowSyntheticDefaultImports
/esModuleInterop
andmodule: nodenext
's"type": "module"
detection interplay in the context of.d.*.ts
files right now is... confusing. Since they are.ts
files, they do currently get assigned apackage.json
-type
-dependent module kind, which determines if the module is made available as adefault
or not on an esm import, and if a cjs file can import it at all, and furthermore we have heuristics involving the presence of adefault
in the declaration file which can then disable the syntheticdefault
creation for interop'd imports (import statements in cjs format files undermodule: nodenext
).This menagerie of behaviors means that to write a declaration file for a json file similar to
["foo", "bar"]
, so is no single way to write it that works for all callers, in all package type contexts, even though json imports (or any non-js import) are not package type dependent.On investigation, I find this state of affairs confusing.
This PR changes how we interpret
.d.*.ts
file module formats to always be cjs-like. This means the correct way to write the declaration file for["foo", "bar"]
is alwaysand registers as importable by all import and require constructs in all package type contexts.