作者:zaizaiwaipo | 来源:互联网 | 2022-12-08 15:00
有没有人知道Node.js v10.x需要哪些目标/库来使用没有生成器的内置async/await?我看到很多节点8但没有节点10.
1> Linus Unnebä..:
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 is on it's way to add ES-Modules, but for now we'll have to stick with CommonJS.
"target": "es2018"
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"]
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
.
The full config would thus be:
{
"compilerOptions": {
"lib": ["es2018"],
"module": "commonjs",
"target": "es2018"
}
}
If you are running Node.js 8 you can see my similar answer for Node.js 8 here
2> Matt McCutch..:
根据推荐的打字原稿配置为节点8,--target ES2017
被支撑在节点8.10.0和较新的(这将包括节点10),并且它足以通过异步函数来输出,而不将它们转换到发电机.
节点10支持100%的ES2018功能,因此您可以定位https://node.green/#ES2018