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: missing types with "moduleResolution": "Node16" #11

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

Conversation

TxHawks
Copy link

@TxHawks TxHawks commented Jun 26, 2022

Since the filename pointed at by default and import (empty) is not identical to the filename of the d.ts file (index), the top level types field is not enough when using "moduleResolution": "Node16" and TypeScript 4.7.

To fix this, types must be explicitly specified inside the exports object in addition to the top level types field.

See firebase/firebase-js-sdk#6300 and microsoft/playwright#14428

Since the filename pointed at by `default` and `import` (`empty`) is not identical to the filename of the `d.ts` file (`index`), the top level `types` field is not enough when using `"moduleResolution":"Node16"` and TypeScript `4.7`. 

To fix this, `types` must be explicitly specified inside the `exports` object in addition to the top level `types` field.

See [firebase/firebase-js-sdk#6300](/firebase/firebase-js-sdk/issues/6300) and [microsoft/playwright#14428](/microsoft/playwright/pull/14428)
@@ -18,7 +18,8 @@
"sideEffects": false,
"exports": {
"default": "./empty.js",
"import": "./empty.js"
"import": "./empty.js",
"types": "./index.d.ts"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per the TS documentation, types should be first in this object? Does not seem to matter in my testing, just pointing out: https://www.typescriptlang.org/docs/handbook/esm-node.html

@mihkeleidast
Copy link

mihkeleidast commented Oct 6, 2022

Hi @kripod, any chance of this getting merged and released? We also ran into this need.

faultyserver added a commit to GamesDoneQuick/react-polymorphic-types that referenced this pull request Apr 18, 2023
As seen in kripod#11, the `types` field needs to be exported for modern node resolution methods to work in typescript.
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.

2 participants