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

Update package.json to support typescript node16 #138

Merged
merged 1 commit into from
Jul 26, 2022

Conversation

wuzzeb
Copy link
Contributor

@wuzzeb wuzzeb commented Jul 25, 2022

To find the types for a package, typescript uses a rule where it finds the ".js" file
for the import and then changes the extension to ".d.ts".

For typescript versions 4.6 and below and typescript 4.7 with moduleResolution "node",
typescript is looking at the "require" entry in "exports" and therefore finds "./dist/index.js"
and then looks for "./dist/index.d.ts" to find the types. This file exists so everything works.

For typescript 4.7 with node16 module resolution, typescript is now looking at the "module"
field and finding "./dist/index.module.js". Typescript then searches for a file "./dist/index.module.d.ts"
to find types, but that file does not exist and typescript produces an error

error TS7016: Could not find a declaration file for module 'use-debounce'.

The fix is just to explicitly specify the path to the types file. This fixes typescript 4.7+
with moduleResolution "node16"

See microsoft/TypeScript#49160 and
https://www.typescriptlang.org/docs/handbook/esm-node.html#packagejson-exports-imports-and-self-referencing

To find the types for a package,  typescript uses a rule where it finds the ".js" file
for the import and then changes the extension to ".d.ts".

For typescript versions 4.6 and below and typescript 4.7 with moduleResolution "node",
typescript is looking at the "require" entry in "exports" and therefore finds "./dist/index.js"
and then looks for "./dist/index.d.ts" to find the types.  This file exists so everything works.

For typescript 4.7 with node16 module resolution, typescript is now looking at the "module"
field and finding "./dist/index.module.js".  Typescript then searches for a file "./dist/index.module.d.ts"
to find types, but that file does not exist and typescript produces an error

error TS7016: Could not find a declaration file for module 'use-debounce'.

The fix is just to explicitly specify the path to the types file.   This fixes typescript 4.7+
with moduleResolution "node16"
@xnimorz
Copy link
Owner

xnimorz commented Jul 26, 2022

Thanks, @wuzzeb! I'll publish it shortly

@xnimorz xnimorz merged commit 9ffa666 into xnimorz:master Jul 26, 2022
@xnimorz
Copy link
Owner

xnimorz commented Jul 26, 2022

Version 8.0.3

Thanks again!

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