简体   繁体   中英

compile typescript code to es6 instead of es5

Currently learning typescript and I noticed that the output code is always using var. Is it possible to output const and let in the .js file or typescript needs to always output es5 for some reason? 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 . See this question: How do I transpile TypeScript to ES6?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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