@types/node-fetch@3.0.3 (latest) does not include an index.d.ts and "typings" is null in package.json
See original GitHub issueDescription
Using node-fetch 2.x with typescript not possible with latest @types/node-fetch@3.0.3 because package does not contain an index.d.ts and in the package.json “typings” is set to null.
Now I understand that this may be a deliberate choice as node-fetch@3.x does contain its types, however there are no instructions for consumers of 2.x on what to do. If the omission of the typings is intentional on @types/node-fetch@3.x then an additional section in the 2.x branch documentation indicating that TypeScript developers using node-fetch@2.x should specifically install @types/node-fetch@2.5.12.
Reproduction
Steps to reproduce the behavior:
- Create a default TypeScript environment.
- Run
npm i node-fetch@2.5.12
. - Run
npm i --save-dev @types/node-fetch
. - Put
import fetch from 'node-fetch'
at the top of your index.ts file. - Run
npx tsc
. - Build fails because
Could not find a declaration file for module 'node-fetch'. 'C:/Users/Foo/Bar/node_modules/node-fetch/lib/index.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/node-fetch` if it exists or add a new declaration (.d.ts) file containing `declare module 'node-fetch';`
Expected behaviour
The module builds successfully.
Suggestions
Option 1
Add the typings back to @types/node-fetch and instruct TypeScript consumers of node-fetch@3.x to not install @types/node-fetch as that is redundant.
Option 2
Add a section in the README.md of the 2.x branch for TypeScript consumers of node-fetch@2.x to install @types/node-fetch@2.5.12
Edit: Also update the typescript section of node-fetch@3.x which instructs the consumers of node-fetch to install @types/node-fetch as that doesn’t work;
For older versions please use the type definitions from DefinitelyTyped:
npm install --save-dev @types/node-fetch
software | version |
---|---|
node-fetch | 2.5.12 |
node | 14.17.5 |
npm | 6.14.14 |
Operating System | Windows 10 |
Issue Analytics
- State:
- Created 2 years ago
- Reactions:6
- Comments:5 (1 by maintainers)
Top GitHub Comments
As a work around in the short term you can have the following in your
package.json
.This issue is more in the lines of either fixing @types/node-fetch@3.x or changing the documentation to specify that to use node-fetch@2.x in ts, @types/node-fetch@2.5.12 must be used.
+1, this is really frustrating… any work being done on this?