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

--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;
}
}
主站蜘蛛池模板: 厦门市| 慈利县| 陕西省| 华坪县| 通辽市| 墨竹工卡县| 陈巴尔虎旗| 肇庆市| 武平县| 台湾省| 信宜市| 三河市| 乳源| 牡丹江市| 九江县| 聊城市| 怀集县| 无锡市| 叶城县| 富平县| 西城区| 牟定县| 汨罗市| 泰州市| 巩留县| 阳新县| 武川县| 新竹市| 新野县| 福贡县| 鹤壁市| 安龙县| 莱芜市| 汶上县| 游戏| 安平县| 东宁县| 开原市| 江门市| 吉林市| 隆德县|