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

--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;
}
}
主站蜘蛛池模板: 夹江县| 保德县| 辛集市| 承德县| 襄垣县| 图片| 曲松县| 安多县| 安塞县| 宁远县| 太和县| 四子王旗| 永泰县| 曲周县| 禄丰县| 嵩明县| 武隆县| 新沂市| 万州区| 合水县| 安义县| 明星| 日土县| 修水县| 惠安县| 化隆| 昌宁县| 南通市| 湘阴县| 鄂托克前旗| 宁南县| 柳林县| 象州县| 凤山市| 邯郸市| 买车| 南投县| 衢州市| 铜梁县| 大丰市| 兴城市|