我想确保我的代码不使用比 ES6 更新的库功能。因此,我的tsconfig.json
看起来像这样:
{
"compilerOptions": {
"lib": [
"es6"
],
"target": "es6",
"outDir": "./dist",
"rootDir": "./src",
"module": "commonjs",
"declaration": true,
"strict": true,
"moduleResolution": "node",
"esModuleInterop": true
}
}
这按预期工作,并且调用类似Object.fromEntries
被标记为错误。
可悲的是,一旦我安装了一些依赖于@types/node
,例如一个 Rollup 插件,TypeScript 在以下声明中选取node_modules/@types/node
:
/// <reference lib="es2018" />
(file node_modules/@types/node/ts3.7/base.d.ts
).
突然,Object.fromEntries
不再被标记,因为 – 尽管我的配置tsconfig.json
– TypeScript 现在加载 ES2018 库。
有什么办法可以避免这种情况吗?