node-fetch: Number of TypeScript type errors
Reproduction
Steps to reproduce the behavior:
yarn install node-fetch(3.2.10)tsc -p tsconfig.json --noEmit- get the following errors:
$ tsc -p tsconfig.json --noEmit
node_modules/fetch-blob/file.d.ts:1:76 - error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.
1 /** @type {typeof globalThis.File} */ export const File: typeof globalThis.File;
~~~~
node_modules/fetch-blob/from.d.ts:20:64 - error TS2749: 'File' refers to a value, but is being used as a type here. Did you mean 'typeof File'?
20 export function fileFrom(path: string, type?: string): Promise<File>;
~~~~
node_modules/fetch-blob/from.d.ts:25:60 - error TS2749: 'File' refers to a value, but is being used as a type here. Did you mean 'typeof File'?
25 export function fileFromSync(path: string, type?: string): File;
~~~~
node_modules/fetch-blob/index.d.ts:2:38 - error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.
2 export const Blob: typeof globalThis.Blob;
~~~~
node_modules/formdata-polyfill/esm.min.d.ts:2:11 - error TS2749: 'FormData' refers to a value, but is being used as a type here. Did you mean 'typeof FormData'?
2 new (): FormData;
~~~~~~~~
node_modules/formdata-polyfill/esm.min.d.ts:3:14 - error TS2749: 'FormData' refers to a value, but is being used as a type here. Did you mean 'typeof FormData'?
3 prototype: FormData;
~~~~~~~~
node_modules/formdata-polyfill/esm.min.d.ts:5:50 - error TS2749: 'FormData' refers to a value, but is being used as a type here. Did you mean 'typeof FormData'?
5 export declare function formDataToBlob(formData: FormData): Blob;
~~~~~~~~
node_modules/node-fetch/@types/index.d.ts:124:4 - error TS2749: 'FormData' refers to a value, but is being used as a type here. Did you mean 'typeof FormData'?
124 | FormData
~~~~~~~~
node_modules/node-fetch/@types/index.d.ts:137:22 - error TS2749: 'FormData' refers to a value, but is being used as a type here. Did you mean 'typeof FormData'?
137 formData(): Promise<FormData>;
~~~~~~~~
Found 9 errors in 5 files.
Errors Files
1 node_modules/fetch-blob/file.d.ts:1
2 node_modules/fetch-blob/from.d.ts:20
1 node_modules/fetch-blob/index.d.ts:2
3 node_modules/formdata-polyfill/esm.min.d.ts:2
2 node_modules/node-fetch/@types/index.d.ts:124
error Command failed with exit code 2.
My tsconfig.json looks like this:
{
"compileOnSave": true,
"compilerOptions": {
"declaration": true,
"esModuleInterop": true,
"lib": ["ES2021"],
"module": "CommonJS",
"noImplicitAny": true,
"noImplicitReturns": true,
"outDir": "dist",
"resolveJsonModule": true,
"rootDir": "src",
"strict": true,
"target": "ES2021",
"typeRoots": ["./src/@types", "./node_modules/@types"]
},
"exclude": ["**/__tests__", "node_modules"],
"include": ["./src/**/*.ts"]
}
Expected behavior
There should be no type errors
Screenshots
Your Environment
| software | version |
|---|---|
| node-fetch | 3.2.10 |
| node | 16.16.0 |
| yarn | 1.22.19 |
| typescript | 4.7.4 |
| Operating System | MacOS 12.4 |
Additional context
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 21
- Comments: 16 (1 by maintainers)
Commits related to this issue
- fix: node-fetch problem node-fetch causing issues when upgrading https://github.com/node-fetch/node-fetch/issues/1617 — committed to autifyhq/autify-cli by 4ydx 8 months ago
Adding “DOM” to tsconfig.json also works as a temporary workaround
But
3.2.8has CVE-2022-2596. @jimmywarting: would you revert the merge of https://github.com/node-fetch/node-fetch/commit/bcfb71c7d10da252280d13818daab6925e12c368?Reverting to
3.2.8works as a workaroundThese errors actually started with version
3.2.9.A better approach than adding
DOM, is to define the following:./src/@types/global.d.ts./tsconfig.jsonNote that
formdata-nodeis necessary for this to work