A consumer using module optionnode16/nodenext and/or or moduleResolution optionnode16/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:
Create a package with module: node16 in its tsconfig.json
Import a type from a package w/ a types field where the type only exists in types.d.ts but not index.js
Observe compilation error
Case B
Otherwise, it's more subtle:
Create a package with module: node16 in its tsconfig.json
Import a type from a package with a types field
Use your editor to navigate to the reference of the type.
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.
Describe the bug
A consumer using
module
optionnode16/nodenext
and/or ormoduleResolution
optionnode16/nodenext
cannot accesstypes.d.ts
from thetypes
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 pointindex.js
doesn't. Assuming that's the case:module: node16
in itstsconfig.json
types
field where the type only exists intypes.d.ts
but notindex.js
Case B
Otherwise, it's more subtle:
module: node16
in itstsconfig.json
types
fieldindex.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.