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

Fix typings when using NodeNext module resolution #2857

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nwalters512
Copy link

@nwalters512 nwalters512 commented Feb 7, 2023

This PR fixes the type declarations to work when moduleResolution is NodeNext. I believe this may be related to microsoft/TypeScript#50690.

Here's a playground illustrating that the current typings work correctly with ESNext module resolution:

https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAMwDYEMZmAYwNZUVCEOAcmTQxymIG4AoWs9LXACgBMJMBXEAUwDsYAOgCOXXlACeAZV5JemGNBbE2wAG7EAlAEIt1IA

Screenshot 2023-02-07 at 11 00 25

And here's the exact same code broken with NodeNext module resolution:

https://www.typescriptlang.org/play?target=99&moduleResolution=99&module=199#code/JYWwDg9gTgLgBAMwDYEMZmAYwNZUVCEOAcmTQxymIG4AoWs9LXACgBMJMBXEAUwDsYAOgCOXXlACeAZV5JemGNBbE2wAG7EAlAEIt1IA

Screenshot 2023-02-07 at 11 00 38

@remcohaszing
Copy link

I’d like to add this is not just for "moduleResolution": "nodenext" or "moduleResolution": "node16", but also for usage with commonjs. module.exports = should always be typed as export =. This was always typed incorrectly, but the new module resolution options make this issue more apparent.

Thank you @nwalters512!

@issei-m
Copy link

issei-m commented Mar 22, 2024

Any news?

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.

None yet

3 participants