TypeScript transitively imports ES libraries

Viewed 228

I want to make sure that my code doesn't use newer library features than ES6. Consequently, my tsconfig.json looks like this:

{
  "compilerOptions": {
    "lib": [
      "es6"
    ],
    "target": "es6",
    "outDir": "./dist",
    "rootDir": "./src",
    "module": "commonjs",
    "declaration": true,
    "strict": true,
    "moduleResolution": "node",
    "esModuleInterop": true
  }
}

This works as expected, and calls like Object.fromEntries are flagged as errors.

Sadly, as soon as I install some dev dependency that depends on @types/node, e.g. a Rollup plugin, TypeScript picks up on the following declaration in node_modules/@types/node:

/// <reference lib="es2018" />

(file node_modules/@types/node/ts3.7/base.d.ts).

Suddendly, Object.fromEntries is not flagged anymore because – despite my config in tsconfig.json – TypeScript now loads the ES2018 library.

Is there any way I can avoid that?

0 Answers
Related