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

types.d.ts inaccessible when using recommended module resolution algorithm #1802

Closed
boneskull opened this issue Oct 2, 2023 · 0 comments · Fixed by #1803
Closed

types.d.ts inaccessible when using recommended module resolution algorithm #1802

boneskull opened this issue Oct 2, 2023 · 0 comments · Fixed by #1803
Labels
bug Something isn't working

Comments

@boneskull
Copy link
Contributor

Describe the bug

A consumer using module option node16/nodenext and/or or moduleResolution option node16/nodenext cannot access types.d.ts from the types field of any package which provides it.

Steps to reproduce

Case A

This won't be obvious unless types.d.ts exports something that the main entry point index.js doesn't. Assuming that's the case:

  1. Create a package with module: node16 in its tsconfig.json
  2. Import a type from a package w/ a types field where the type only exists in types.d.ts but not index.js
  3. Observe compilation error

Case B

Otherwise, it's more subtle:

  1. Create a package with module: node16 in its tsconfig.json
  2. Import a type from a package with a types field
  3. Use your editor to navigate to the reference of the type.
  4. You will navigate to index.js.

Expected behavior

Case A: no error
Case B: should have navigated to types.d.ts

Platform environment

n/a

Additional context

This is not a problem when using the legacy node module resolution algorithm.

The solution is to add a types conditional export, as you will read in the documentation linked above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant