配置較少的程式設計錯誤
有很好的配置可以強制輸入並獲得更多有用的錯誤,預設情況下不會啟用這些錯誤。
{
"compilerOptions": {
"alwaysStrict": true, // Parse in strict mode and emit "use strict" for each source file.
// If you have wrong casing in referenced files e.g. the filename is Global.ts and you have a /// <reference path="global.ts" /> to reference this file, then this can cause to unexpected errors. Visite: http://stackoverflow.com/questions/36628612/typescript-transpiler-casing-issue
"forceConsistentCasingInFileNames": true, // Disallow inconsistently-cased references to the same file.
// "allowUnreachableCode": false, // Do not report errors on unreachable code. (Default: False)
// "allowUnusedLabels": false, // Do not report errors on unused labels. (Default: False)
"noFallthroughCasesInSwitch": true, // Report errors for fall through cases in switch statement.
"noImplicitReturns": true, // Report error when not all code paths in function return a value.
"noUnusedParameters": true, // Report errors on unused parameters.
"noUnusedLocals": true, // Report errors on unused locals.
"noImplicitAny": true, // Raise error on expressions and declarations with an implied "any" type.
"noImplicitThis": true, // Raise error on this expressions with an implied "any" type.
"strictNullChecks": true, // The null and undefined values are not in the domain of every type and are only assignable to themselves and any.
// To enforce this rules, add this configuration.
"noEmitOnError": true // Do not emit outputs if any errors were reported.
}
}
不夠?如果你是一個硬編碼器並想要更多,那麼你可能有興趣用 tslint 檢查你的 TypeScript 檔案,然後用 tsc 編譯它。檢查如何為更嚴格的程式碼配置 tslint 。