Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
119 views
in Technique[技术] by (71.8m points)

TypeScript tsconfig settings for Node.js 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.

question from:https://stackoverflow.com/questions/51716406/typescript-tsconfig-settings-for-node-js-10

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 14 you can see my similar answer for Node.js 14 here

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...