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

--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;
}
}
主站蜘蛛池模板: 庐江县| 荣昌县| 商洛市| 建宁县| 凤阳县| 永泰县| 衡山县| 南京市| 吴旗县| 酒泉市| 砚山县| 太和县| 山阴县| 定襄县| 渭源县| 麟游县| 永福县| 达孜县| 临江市| 哈巴河县| 连州市| 桂林市| 永城市| 中江县| 广平县| 南投县| 临沂市| 花莲县| 兴安县| 翼城县| 芜湖县| 尚义县| 辽中县| 江山市| 青海省| 蒙山县| 屏东县| 都安| 满洲里市| 驻马店市| 西华县|