Skip to content

Commit e53e56c

Browse files
author
Andy
authored
Enable '--strictNullChecks' (#22088)
* Enable '--strictNullChecks' * Fix API baselines * Make sys.getEnvironmentVariable non-nullable * make properties optional instead of using `| undefined` in thier type * reportDiagnostics should be required * Declare firstAccessor as non-nullable * Make `some` a type guard * Fix `getEnvironmentVariable` definition in tests * Pretend transformFlags are always defined * Fix one more use of sys.getEnvironmentVariable * `requiredResponse` accepts undefined, remove assertions * Mark optional properties as optional instead of using `| undefined` * Mark optional properties as optional instead of using ` | undefined` * Remove unnecessary null assertions * Put the bang on the declaration instead of every use * Make `createMapFromTemplate` require a parameter * Mark `EmitResult.emittedFiles` and `EmitResult.sourceMaps` as optional * Plumb through undefined in emitLsit and EmitExpressionList * `ElementAccessExpression.argumentExpression` can not be `undefined` * Add overloads for `writeTokenText` * Make `shouldWriteSeparatingLineTerminator` argument non-nullable * Make `synthesizedNodeStartsOnNewLine` argument required * `PropertyAssignment.initializer` cannot be undefined * Use one `!` at declaration site instead of on every use site * Capture host in a constant and avoid null assertions * Remove few more unused assertions * Update baselines * Use parameter defaults * Update baselines * Fix lint * Make Symbol#valueDeclaration and Symbol#declarations non-optional to reduce assertions * Make Node#symbol and Type#symbol non-optional to reduce assertions * Make `flags` non-nullable to reduce assertions * Convert some asserts to type guards * Make `isNonLocalAlias` a type guard * Add overload for `getSymbolOfNode` for `Declaration` * Some more `getSymbolOfNode` changes * Push undefined suppression into `typeToTypeNodeHelper` * `NodeBuilderContext.tracker` is never `undefined` * use `Debug.assertDefined` * Remove unnecessary tag * Mark `LiteralType.freshType` and `LiteralTupe.regularType` as required
1 parent 3fe946d commit e53e56c

File tree

167 files changed

+4842
-4731
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

167 files changed

+4842
-4731
lines changed

Gulpfile.js

+1
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ function getCompilerSettings(base, useBuiltCompiler) {
260260
for (const key in base) {
261261
copy[key] = base[key];
262262
}
263+
copy.strictNullChecks = true;
263264
if (!useDebugMode) {
264265
if (copy.removeComments === undefined) copy.removeComments = true;
265266
}

Jakefile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, opts
251251
else {
252252
options += " --lib es5";
253253
}
254-
options += " --noUnusedLocals --noUnusedParameters";
254+
options += " --noUnusedLocals --noUnusedParameters --strictNullChecks";
255255

256256
var cmd = host + " " + compilerPath + " " + options + " ";
257257
cmd = cmd + sources.join(" ");

scripts/buildProtocol.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function endsWith(s: string, suffix: string) {
88
}
99

1010
function isStringEnum(declaration: ts.EnumDeclaration) {
11-
return declaration.members.length && declaration.members.every(m => m.initializer && m.initializer.kind === ts.SyntaxKind.StringLiteral);
11+
return declaration.members.length && declaration.members.every(m => !!m.initializer && m.initializer.kind === ts.SyntaxKind.StringLiteral);
1212
}
1313

1414
class DeclarationsWalker {
@@ -30,7 +30,7 @@ class DeclarationsWalker {
3030
text += "\ndeclare namespace ts {\n";
3131
text += " // these types are empty stubs for types from services and should not be used directly\n"
3232
for (const type of walker.removedTypes) {
33-
text += ` export type ${type.symbol.name} = never;\n`;
33+
text += ` export type ${type.symbol!.name} = never;\n`;
3434
}
3535
text += "}"
3636
}
@@ -130,7 +130,7 @@ function writeProtocolFile(outputFile: string, protocolTs: string, typeScriptSer
130130
function getInitialDtsFileForProtocol() {
131131
const program = ts.createProgram([protocolTs, typeScriptServicesDts], options);
132132

133-
let protocolDts: string;
133+
let protocolDts: string | undefined;
134134
program.emit(program.getSourceFile(protocolTs), (file, content) => {
135135
if (endsWith(file, ".d.ts")) {
136136
protocolDts = content;
@@ -162,7 +162,7 @@ function writeProtocolFile(outputFile: string, protocolTs: string, typeScriptSer
162162
let protocolDts = getInitialDtsFileForProtocol();
163163
const program = getProgramWithProtocolText(protocolDts, /*includeTypeScriptServices*/ true);
164164

165-
const protocolFile = program.getSourceFile("protocol.d.ts");
165+
const protocolFile = program.getSourceFile("protocol.d.ts")!;
166166
const extraDeclarations = DeclarationsWalker.getExtraDeclarations(program.getTypeChecker(), protocolFile);
167167
if (extraDeclarations) {
168168
protocolDts += extraDeclarations;

scripts/processDiagnosticMessages.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function main(): void {
2222
}
2323

2424
const inputFilePath = sys.args[0].replace(/\\/g, "/");
25-
const inputStr = sys.readFile(inputFilePath);
25+
const inputStr = sys.readFile(inputFilePath)!;
2626

2727
const diagnosticMessagesJson: { [key: string]: DiagnosticDetails } = JSON.parse(inputStr);
2828

scripts/tslint/rules/noInOperatorRule.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class Rule extends Lint.Rules.AbstractRule {
1212
function walk(ctx: Lint.WalkContext<void>): void {
1313
ts.forEachChild(ctx.sourceFile, recur);
1414
function recur(node: ts.Node): void {
15-
if (node.kind === ts.SyntaxKind.InKeyword && node.parent.kind === ts.SyntaxKind.BinaryExpression) {
15+
if (node.kind === ts.SyntaxKind.InKeyword && node.parent!.kind === ts.SyntaxKind.BinaryExpression) {
1616
ctx.addFailureAtNode(node, Rule.FAILURE_STRING);
1717
}
1818
}

scripts/tslint/rules/noUnnecessaryTypeAssertion2Rule.ts

-98
This file was deleted.

0 commit comments

Comments
 (0)