question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Number of TypeScript type errors

See original GitHub issue

Reproduction

Steps to reproduce the behavior:

  1. yarn install node-fetch (3.2.10)
  2. tsc -p tsconfig.json --noEmit
  3. 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

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:11
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
alive2commented, Aug 30, 2022

Adding “DOM” to tsconfig.json also works as a temporary workaround

{
    "compilerOptions": {
        ...
        "lib": ["es2017", "esnext.asynciterable", "DOM"],
        ...
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - Understanding Errors - TypeScript
Understanding Errors. Whenever TypeScript finds an error, it tries to explain what went wrong in as much detail as possible. Because its type...
Read more >
TypeScript errors and how to fix them
Common Errors. Below you find a list of common TypeScript errors along with the buggy code and its fixed version. If you're interested...
Read more >
Complete list of Typescript error codes and their fixes
I expect you post an answer regarding the new Typescript (currently 1.6 is the most recent).
Read more >
Improving TypeScript error handling with exhaustive type ...
Discover an improved method for handling errors in TypeScript that solves problems that arise from returning null and throwing try...catch.
Read more >
Type-Safe Error Handling In TypeScript - DEV Community ‍ ‍
import { ok, err, Result } from 'neverthrow' // we'll keep this simple type ResponseBody = {} interface ResponseData { statusCode: number ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found