配置较少的编程错误
有很好的配置可以强制输入并获得更多有用的错误,默认情况下不会激活这些错误。
{
"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 。