- Learn React with TypeScript 3
- Carl Rippon
- 162字
- 2021-06-10 19:16:37
--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;
}
}
- C++面向對象程序設計(第三版)
- Modular Programming with Python
- 新手學Visual C# 2008程序設計
- Java Web開發技術教程
- 用Flutter極速構建原生應用
- 你不知道的JavaScript(中卷)
- FLL+WRO樂高機器人競賽教程:機械、巡線與PID
- 零基礎學Python網絡爬蟲案例實戰全流程詳解(入門與提高篇)
- ElasticSearch Cookbook(Second Edition)
- Geospatial Development By Example with Python
- JavaScript應用開發實踐指南
- 遠方:兩位持續創業者的點滴思考
- Mastering Leap Motion
- Getting Started with Web Components
- Android初級應用開發