首页 > 其他 > 详细

[Typescript] Understanding “lib” and ES libraries

时间:2020-10-05 22:00:52      阅读:20      评论:0      收藏:0      [点我收藏+]

Sometime if our tsconfig.json looks like this;

{
    "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "outDir": "dist"
    }
}

 

We can get all kinds of type autocomplete in VSCode such as :

Array.isArray([])

 

But we don‘t have:

Array.from(document.queryElmentsById(‘button‘))

it shows red underline.

 

This is because we are just targeting "es5":

"target": "es5",

 

To solve the issues, we can use:

{
    "compilerOptions": {
        "target": "es5",
        "lib": ["es6"],
        "module": "commonjs",
        "outDir": "dist"
    }
}

 

But now, we have another problem for "docuemnt".

to fix this:

{
    "compilerOptions": {
        "target": "es5",
        "lib": ["es6", "dom"],
        "module": "commonjs",
        "outDir": "dist"
    }
}

 

[Typescript] Understanding “lib” and ES libraries

原文:https://www.cnblogs.com/Answer1215/p/13770573.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!