Node.js 10的TypeScript tsconfig设置? [英] TypeScript tsconfig settings for Node.js 10?

查看:125
本文介绍了Node.js 10的TypeScript tsconfig设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道Node.js v10.x在没有生成器的情况下使用内置的async/await时需要哪些目标/库吗?我在节点8上看到很多,但在节点10上却看不到.

Does anyone know which target/libs are required for Node.js v10.x to use the built in async/await without the generators? I see a lot for node 8 but not with node 10.

推荐答案

从Node.js 10.0.0开始,支持100%的ES2018.如果您知道要定位该版本或更高版本,则最佳配置应如下所示:

As of Node.js 10.0.0, 100% of ES2018 is supported. If you know that you are targeting that version or newer, the optimal config would look like this:

  • "module": "commonjs"

Node.js可以添加ES模块,但是现在我们必须坚持使用CommonJS.

Node.js is on it's way to add ES-Modules, but for now we'll have to stick with CommonJS.

"target": "es2018"

这告诉TypeScript可以输出具有ES2018中功能的JavaScript 语法.实际上,这意味着它将例如输出对象的剩余/扩展属性& async/await语法,而不是嵌入polyfill.

This tells TypeScript that it's okay to output JavaScript syntax with features from ES2018. In practice, this means that it will e.g. output object rest/spread properties & async/await syntax instead of embedding a polyfill.

"lib": ["es2018"]

这告诉TypeScript可以使用ES2018或更早版本中引入的功能和属性.实际上,这意味着您可以使用Promise.prototype.finallyArray.prototype.includesString.prototype.padStart.

This tells TypeScript that it's okay to use functions and properties introduced in ES2018 or earlier. In practice, this means that you can use e.g. Promise.prototype.finally, Array.prototype.includes and String.prototype.padStart.

因此,完整的配置为:

{
  "compilerOptions": {
    "lib": ["es2018"],
    "module": "commonjs",
    "target": "es2018"
  }
}


如果您正在运行Node.js 14,则可以在此处看到我的针对Node.js 14的类似答案

如果您正在运行Node.js 12,则可以在此处看到我的针对Node.js 12的类似答案

If you are running Node.js 12 you can see my similar answer for Node.js 12 here

如果您正在运行Node.js 8,则可以在此处看到我的针对Node.js 8的类似答案

If you are running Node.js 8 you can see my similar answer for Node.js 8 here

这篇关于Node.js 10的TypeScript tsconfig设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆