-
Compiler Options(compilerOptions)
-
Type Checking
-
Allow Unreachable Code - allowUnreachableCode
-
Unreachable Code指的是永遠不會被執行到的程式碼
function test() { return "done"; console.log("這行永遠不會執行"); // Unreachable Code }
-
values
undefined(default) 提供警告建議
true 忽略
false compiler階段直接error -
Released: 1.8
-
-
Allow Unused Labels - allowUnusedLabels
-
javascript中可以使用label標記陳述式並且搭配break、continue
function foo() { test: { // 這裡宣告了一個 label "test" console.log("hello"); } // 但程式裡沒有用 break/continue test; => 所以它是 unused label } -
values
undefined (default) 提供警告建議 true 忽略 false compiler階段直接error
-
Released: 1.8
-
-
Always Strict - alwaysStrict
-
關於Strict Mode可以看這篇 [JavaScript]-Strict Mode, 啟用的話在編譯輸出的時候都會每個檔案都會加上'use strict'。
-
values
default true if strict; false
-
Related
-
Released: 2.1
-
-
Exact Optional Property Types - exactOptionalPropertyTypes
-
當啟用exactOptionalPropertyTypes,TypeScript會對 *?*進行更嚴格的處理方式,例子如下
interface UserDefaults { colorThemeOverride?: "dark" | "light"; } const settings = getUserSettings(); settings.colorThemeOverride = undefined; // !注意這行當啟用這項屬性的時候例子中的
settings.colorThemeOverride = undefined就會出現警告、錯誤, 不啟用的話上面的UserDefaults可以看成是interface UserDefaults { colorThemeOverride: "dark" | "light" | "undefined" } -
values
true、false
-
Released: 4.4
-
-
-
No Fallthrough Cases In Switch - noFallthroughCasesInSwitch
-
當啟用時若switch表達式 case中有無break、return、throw等關鍵字會出現錯誤,不啟用的情況下 case或是沒有break、return、throw會進入下一個case。
switch (a) { case 0: // Fallthrough case in switch case 1: break; } -
values
true、false
-
Released: 1.8
-
-
No Implicit Any - noImplicitAny
-