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
This commit is contained in:
Andy
2018-05-22 14:46:57 -07:00
committed by GitHub
parent 3fe946df78
commit e53e56cf82
167 changed files with 4846 additions and 4735 deletions

View File

@@ -14,11 +14,11 @@ namespace ts.server {
* The script version cache is generated on demand and text is still retained.
* Only on edits to the script version cache, the text will be set to undefined
*/
private text: string;
private text: string | undefined;
/**
* Line map for the text when there is no script version cache present
*/
private lineMap: number[];
private lineMap: number[] | undefined;
private textVersion = 0;
/**
@@ -115,7 +115,7 @@ namespace ts.server {
public getSnapshot(): IScriptSnapshot {
return this.useScriptVersionCacheIfValidOrOpen()
? this.svc.getSnapshot()
? this.svc!.getSnapshot()
: ScriptSnapshot.fromString(this.getOrLoadText());
}
@@ -129,10 +129,10 @@ namespace ts.server {
if (!this.useScriptVersionCacheIfValidOrOpen()) {
const lineMap = this.getLineMap();
const start = lineMap[line]; // -1 since line is 1-based
const end = line + 1 < lineMap.length ? lineMap[line + 1] : this.text.length;
const end = line + 1 < lineMap.length ? lineMap[line + 1] : this.text!.length;
return createTextSpanFromBounds(start, end);
}
return this.svc.lineToTextSpan(line);
return this.svc!.lineToTextSpan(line);
}
/**
@@ -145,7 +145,7 @@ namespace ts.server {
}
// TODO: assert this offset is actually on the line
return this.svc.lineOffsetToPosition(line, offset);
return this.svc!.lineOffsetToPosition(line, offset);
}
positionToLineOffset(position: number): protocol.Location {
@@ -153,7 +153,7 @@ namespace ts.server {
const { line, character } = computeLineAndCharacterOfPosition(this.getLineMap(), position);
return { line: line + 1, offset: character + 1 };
}
return this.svc.positionToLineOffset(position);
return this.svc!.positionToLineOffset(position);
}
private getFileText(tempFileName?: string) {
@@ -188,7 +188,7 @@ namespace ts.server {
Debug.assert(!this.svc || this.pendingReloadFromDisk, "ScriptVersionCache should not be set when reloading from disk");
this.reloadWithFileText();
}
return this.text;
return this.text!;
}
private getLineMap() {
@@ -217,7 +217,7 @@ namespace ts.server {
private preferences: UserPreferences | undefined;
/* @internal */
fileWatcher: FileWatcher;
fileWatcher: FileWatcher | undefined;
private textStorage: TextStorage;
/*@internal*/
@@ -294,7 +294,7 @@ namespace ts.server {
this.realpath = project.toPath(realpath);
// If it is different from this.path, add to the map
if (this.realpath !== this.path) {
project.projectService.realpathToScriptInfos.add(this.realpath, this);
project.projectService.realpathToScriptInfos!.add(this.realpath, this); // TODO: GH#18217
}
}
}
@@ -306,8 +306,8 @@ namespace ts.server {
return this.realpath && this.realpath !== this.path ? this.realpath : undefined;
}
getFormatCodeSettings(): FormatCodeSettings { return this.formatSettings; }
getPreferences(): UserPreferences { return this.preferences; }
getFormatCodeSettings(): FormatCodeSettings | undefined { return this.formatSettings; }
getPreferences(): UserPreferences | undefined { return this.preferences; }
attachToProject(project: Project): boolean {
const isNew = !this.isAttached(project);
@@ -345,7 +345,7 @@ namespace ts.server {
case 2:
if (this.containingProjects[0] === project) {
project.onFileAddedOrRemoved();
this.containingProjects[0] = this.containingProjects.pop();
this.containingProjects[0] = this.containingProjects.pop()!;
}
else if (this.containingProjects[1] === project) {
project.onFileAddedOrRemoved();
@@ -406,7 +406,7 @@ namespace ts.server {
}
}
setOptions(formatSettings: FormatCodeSettings, preferences: UserPreferences): void {
setOptions(formatSettings: FormatCodeSettings, preferences: UserPreferences | undefined): void {
if (formatSettings) {
if (!this.formatSettings) {
this.formatSettings = getDefaultFormatCodeSettings(this.host);