endojs / endo

Endo is a distributed secure JavaScript sandbox, based on SES
Apache License 2.0
829 stars 72 forks source link

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

Closed boneskull closed 11 months ago

boneskull commented 1 year ago

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.