fix: Solved issue with importing @pollyjs projects in TypesScript #500
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.
When importing a dependency with multiple module types, TypeScript needs each type of module to have its own type declaration file, and ES module files must have the corresponding extensions (.mjs and .mts).
Description
mjs
extension for ES module build output.types.d.ts
file to the respective dist folders.Motivation and Context
microsoft/TypeScript#50466
Specifically the issue here is when you use the Node16 or NodeNext moduleResolution mode in a TypeScript project w/ and corresponding module target,
tsc
errors witherror TS2351: This expression is not constructable. Type 'typeof import("node_modules/@pollyjs/adapter-node-http/types")' has no construct signatures.
. This is becausetsc
's type checker is interpreting the module as a CommonJS module, and when a CommonJS module has this type of default export declaration it is necessary to explicitly extract thedefault
property. Here's an example project to reproduce the issue:package.json
tsconfig.json
index.ts
While I would argue that TypeScript could do better here, the maintainers are showing no signs of resolving this or even taking the issue seriously.
Types of Changes
Checklist