- 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;
}
}
- Boost.Asio C++ Network Programming(Second Edition)
- Getting Started with React
- Building a Home Security System with Raspberry Pi
- Xcode 7 Essentials(Second Edition)
- 基于Swift語言的iOS App 商業實戰教程
- ArcGIS By Example
- TypeScript項目開發實戰
- C#程序設計基礎:教程、實驗、習題
- Unity 3D腳本編程:使用C#語言開發跨平臺游戲
- Solutions Architect's Handbook
- Mastering Adobe Captivate 7
- Python硬件編程實戰
- Swift High Performance
- Getting Started with the Lazarus IDE
- Learning Zimbra Server Essentials