typescript - TypeScript 可传递地导入 ES 库
问题描述
我想确保我的代码不使用比 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" />
(文件node_modules/@types/node/ts3.7/base.d.ts
)。
突然,Object.fromEntries
不再被标记,因为——尽管我在其中进行了配置tsconfig.json
——TypeScript 现在加载了 ES2018 库。
有什么办法可以避免吗?
解决方案
推荐阅读
- autohotkey - 在两个显示器之间移动鼠标
- powershell - 使用 SharePoint Online PowerShell 从模板创建文档库
- fabricjs - 没有fragmentSource的FabricJS图像过滤器?
- xamarin - 单击“返回”按钮时如何在选项卡之间导航
- c# - 共享相同文本框并返回不同值的 Devexpress 组合框
- batch-file - 如何创建快捷方式或批处理文件来终止进程
- angular - 对象字面量只能指定已知属性,并且在“IndividualSeriesOptions”类型中不存在“标记”
- php - 从 html 表中删除记录,但保留在数据库表中
- ios - UITableView (Swift 4) 中的奇怪缓存问题
- c# - 多次显示和隐藏带有幻灯片动画的 WPF 窗口,同时每次都一致地显示动画