◆
TypeScript tsconfig lib 配置指定引入库文件
作用
这个是用于指定要引入的库文件,
- 属性值为一个数组,如 `['DOM', 'ES6', 'ES7', 'ESNext'] 等。
手动设置
当手动设置 lib 时,比如将 lib 设置为 ['ES6''],我们没有将 DOM 加入到 lib 中。
这时我们使用 dom 的语法将会报错
如下代码
export const body = document.getElementsByClassName('body');
报错提示
TS2584: Cannot find name 'document'. Do you need to change your target library? Try changing the 'lib' compiler option to include 'dom'.
根据提示我们需要将 DOM 添加到 lib 中,这样才能使用 document
默认库
如果你没有指定 --lib,则会导入默认库:
target 选项为 es5 时,会导入 es5, dom, scripthost。 target 选项为 es6 时,会导入 es6, dom, dom.iterable, scripthost。

还没有留言,来发表第一条吧~