简体   繁体   English

将打字稿代码编译为 es6 而不是 es5

[英]compile typescript code to es6 instead of es5

Currently learning typescript and I noticed that the output code is always using var.目前正在学习打字稿,我注意到输出代码总是使用 var。 Is it possible to output const and let in the .js file or typescript needs to always output es5 for some reason?是否可以输出 const 并让 .js 文件或 typescript 出于某种原因需要始终输出 es5? Thanks.谢谢。

EXAMPLE:例子:

// main.ts
const x: number = 2;
let y: string = 'hello';

// main.js
var x = 2;
var y = 'hello';

Is this output possible, if so, how?这个输出是否可能,如果是,如何?

// main.js
const x = 2;
let y = 'hello';

You can add compiler flags to specify a target, eg --target es6 .您可以添加编译器标志来指定目标,例如--target es6 See this question: How do I transpile TypeScript to ES6?请参阅此问题: 如何将 TypeScript 转换为 ES6?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM