- Learn React with TypeScript 3
- Carl Rippon
- 141字
- 2021-06-10 19:16:38
--watch
This option makes the TypeScript compiler run indefinitely. Whenever a source file is changed, the compiling process is triggered automatically to generate the new version. This is a useful option to switch on during our developments:
- Let's give this a try by entering the following in a terminal:
tsc orderDetail --watch
- The compiler should run and, when completed, give the message Watching for file changes. Let's change the getTotal method in the OrderDetail class to handle situations when discount is undefined:
getTotal(discount: number): number {
const priceWithoutDiscount = this.product.unitPrice * this.quantity;
const discountAmount = priceWithoutDiscount * (discount || 0);
return priceWithoutDiscount - discountAmount;
}
- When we save orderDetail.ts, the compiler will say File change detected. Starting incremental compilation... and carry out the compilation.
To exit the watch mode, we can kill the terminal by clicking the bin icon in the Terminal.
推薦閱讀
- 數據科學實戰手冊(R+Python)
- Mastering NetBeans
- C#編程入門指南(上下冊)
- Mastering Python Scripting for System Administrators
- Java Web及其框架技術
- Designing Hyper-V Solutions
- Python進階編程:編寫更高效、優雅的Python代碼
- Web Application Development with MEAN
- 軟件架構:Python語言實現
- Swift Playgrounds少兒趣編程
- 愛上micro:bit
- 零代碼實戰:企業級應用搭建與案例詳解
- 硬件產品設計與開發:從原型到交付
- 算法圖解
- Python機器學習開發實戰