Node.js 10 的 TypeScript tsconfig 设置? [英] TypeScript tsconfig settings for Node.js 10?
问题描述
有谁知道 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:
模块":commonjs"
Node.js 正在添加 ES-Modules,但现在我们必须坚持使用 CommonJS.
Node.js is on its way to add ES-Modules, but for now we'll have to stick with CommonJS.
目标":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.finally
、Array.prototype.includes
和 String.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 16,您可以在此处查看我的 Node.js 16 的类似答案
如果您正在运行 Node.js 14,您可以在此处查看我的 Node.js 14 的类似答案
If you are running Node.js 14 you can see my similar answer for Node.js 14 here
如果您正在运行 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屋!