typescript - Ignorera DOM-typningar i VSCode


Jag har Visual Studio Code 1.51.1 (egentligen VSCodium) och TypeScript 4.0.3. Givet ett stort projekt för NodeJS och denna tsconfig.json-fil:

{
  "compilerOptions": {
    "alwaysStrict": true,
    "noImplicitAny": true,
    "strictBindCallApply": true,
    "strictFunctionTypes": true,
    "baseUrl": ".",
    "esModuleInterop": true,
    "incremental": true,
    "outDir": "dist",
    "module": "CommonJS",
    "resolveJsonModule": true,
    "rootDir": ".",
    "sourceMap": true,
    "target": "ES2019",
    "lib": ["ES2019"],
    "typeRoots": ["./node_modules/@types"]
  },
  "typeRoots": ["*.d.ts"]
}
  

Jag får fortfarande förslag för DOM (webbläsar-API) från lib.dom.d.ts i själva applikationspaketet:

/Applications/VSCodium.app/Contents/Resources/app/extensions/node_modules/typescript/lib/lib.dom.d.ts

Jag försökte sätta noLib: false men tsc klagar att det strider mot lib-alternativet. Hur kan jag se till att VSCode gör rätt? Missar jag något? När jag försöker göra en repro på ett litet projekt verkar det fungera fint.

Svar #1

Uteslut node_modules från tsconfig.json så att det slutar klaga på externa paket:

{
  "compilerOptions": {
    "alwaysStrict": true,
    "noImplicitAny": true,
    "strictBindCallApply": true,
    "strictFunctionTypes": true,
    "baseUrl": ".",
    "esModuleInterop": true,
    "incremental": true,
    "outDir": "dist",
    "module": "CommonJS",
    "resolveJsonModule": true,
    "rootDir": ".",
    "sourceMap": true,
    "target": "ES2019",
    "lib": ["ES2019"],
    "typeRoots": ["./node_modules/@types"]
  },
  "typeRoots": ["*.d.ts"],
  "exclude": ["node_modules"]
}

Svar #2

Jag begränsade det till att använda @types/supertest som beror på @types/superagent. I deras typdefinitioner importerar de DOM-API:et. Det finns ett aktuellt problem på GitHub: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/41425