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

--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;
}
}
主站蜘蛛池模板: 临海市| 台北市| 信宜市| 郯城县| 清苑县| 察哈| 黄浦区| 河东区| 郧西县| 远安县| 宁波市| 新营市| 瓮安县| 河源市| 如皋市| 永善县| 泽州县| 平果县| 河北省| 富顺县| 东宁县| 洛隆县| 都匀市| 晋中市| 涟水县| 连州市| 定边县| 门头沟区| 桃江县| 桃园县| 河间市| 清流县| 曲靖市| 马公市| 积石山| 讷河市| 乐清市| 茂名市| 资兴市| 即墨市| 泗水县|