Update package.json to support typescript node16 #138
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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