官术网_书友最值得收藏!

--target

This determines the ECMAScript version the transpiled code will be generated in.

The default is ES3, which will ensure the code works in a wide range of browsers and their different versions. However, this compilation target will generate the most amount of code because the compiler will generate polyfill code for features that aren't supported in ES3.

The ESNext option is the other extreme, which compiles to the latest supported proposed ES features. This will generate the least amount of code, but will only work on browsers that have implemented the features we have used.

As an example, let's compile orderDetail.ts targeting ES6 browsers. Enter the following in the terminal:

tsc orderDetail --target es6

Our transpiled JavaScript will be very different from the last compilation and much closer to our source TypeScript because classes are supported in es6:

export class OrderDetail {
getTotal(discount) {
const priceWithoutDiscount = this.product.unitPrice * this.quantity;
const discountAmount = priceWithoutDiscount * discount;
return priceWithoutDiscount - discountAmount;
}
}
主站蜘蛛池模板: 墨江| 通榆县| 且末县| 佛冈县| 金湖县| 罗城| 江门市| 浮山县| 香格里拉县| 通江县| 高唐县| 长岛县| 新疆| 信宜市| 呼和浩特市| 曲周县| 德江县| 延吉市| 科尔| 老河口市| 湟源县| 龙山县| 怀集县| 若尔盖县| 元朗区| 泉州市| 会昌县| 永新县| 朝阳市| 萨迦县| 和平区| 左权县| 凤山市| 静乐县| 镶黄旗| 万全县| 英山县| 淳安县| 合肥市| 垣曲县| 墨脱县|