Enable --strictPropertyInitialization (#27558)

* Enable --strictPropertyInitialization

* Code review
This commit is contained in:
Andy
2018-11-16 16:02:23 -08:00
committed by GitHub
parent 6bb1ff2214
commit 12f3d0d54c
26 changed files with 168 additions and 165 deletions

View File

@@ -479,7 +479,7 @@ namespace ts.server {
*/
private readonly openFilesWithNonRootedDiskPath = createMap<ScriptInfo>();
private compilerOptionsForInferredProjects: CompilerOptions;
private compilerOptionsForInferredProjects: CompilerOptions | undefined;
private compilerOptionsForInferredProjectsPerProjectRoot = createMap<CompilerOptions>();
/**
* Project size for configured or external projects
@@ -501,7 +501,7 @@ namespace ts.server {
private pendingProjectUpdates = createMap<Project>();
/* @internal */
pendingEnsureProjectForOpenFiles: boolean;
pendingEnsureProjectForOpenFiles = false;
readonly currentDirectory: NormalizedPath;
readonly toCanonicalFileName: (f: string) => string;
@@ -1936,7 +1936,7 @@ namespace ts.server {
}
private createInferredProject(currentDirectory: string | undefined, isSingleInferredProject?: boolean, projectRootPath?: NormalizedPath): InferredProject {
const compilerOptions = projectRootPath && this.compilerOptionsForInferredProjectsPerProjectRoot.get(projectRootPath) || this.compilerOptionsForInferredProjects;
const compilerOptions = projectRootPath && this.compilerOptionsForInferredProjectsPerProjectRoot.get(projectRootPath) || this.compilerOptionsForInferredProjects!; // TODO: GH#18217
const project = new InferredProject(this, this.documentRegistry, compilerOptions, projectRootPath, currentDirectory, this.currentPluginConfigOverrides);
if (isSingleInferredProject) {
this.inferredProjects.unshift(project);

View File

@@ -112,9 +112,9 @@ namespace ts.server {
export abstract class Project implements LanguageServiceHost, ModuleResolutionHost {
private rootFiles: ScriptInfo[] = [];
private rootFilesMap: Map<ProjectRoot> = createMap<ProjectRoot>();
private program: Program;
private externalFiles: SortedReadonlyArray<string>;
private missingFilesMap: Map<FileWatcher>;
private program: Program | undefined;
private externalFiles: SortedReadonlyArray<string> | undefined;
private missingFilesMap: Map<FileWatcher> | undefined;
private plugins: PluginModuleWithName[] = [];
/*@internal*/
@@ -141,7 +141,7 @@ namespace ts.server {
readonly realpath?: (path: string) => string;
/*@internal*/
hasInvalidatedResolution: HasInvalidatedResolution;
hasInvalidatedResolution: HasInvalidatedResolution | undefined;
/*@internal*/
resolutionCache: ResolutionCache;
@@ -154,7 +154,7 @@ namespace ts.server {
/**
* Set of files that was returned from the last call to getChangesSinceVersion.
*/
private lastReportedFileNames: Map<true>;
private lastReportedFileNames: Map<true> | undefined;
/**
* Last version that was reported.
*/
@@ -512,8 +512,8 @@ namespace ts.server {
return [];
}
updateProjectIfDirty(this);
this.builderState = BuilderState.create(this.program, this.projectService.toCanonicalFileName, this.builderState);
return mapDefined(BuilderState.getFilesAffectedBy(this.builderState, this.program, scriptInfo.path, this.cancellationToken, data => this.projectService.host.createHash!(data)), // TODO: GH#18217
this.builderState = BuilderState.create(this.program!, this.projectService.toCanonicalFileName, this.builderState);
return mapDefined(BuilderState.getFilesAffectedBy(this.builderState, this.program!, scriptInfo.path, this.cancellationToken, data => this.projectService.host.createHash!(data)), // TODO: GH#18217
sourceFile => this.shouldEmitFile(this.projectService.getScriptInfoForPath(sourceFile.path)!) ? sourceFile.fileName : undefined);
}
@@ -594,7 +594,7 @@ namespace ts.server {
/* @internal */
getSourceFileOrConfigFile(path: Path): SourceFile | undefined {
const options = this.program.getCompilerOptions();
const options = this.program!.getCompilerOptions();
return path === options.configFilePath ? options.configFile : this.getSourceFile(path);
}
@@ -681,7 +681,7 @@ namespace ts.server {
// if language service is not enabled - return just root files
return this.rootFiles;
}
return map(this.program.getSourceFiles(), sourceFile => {
return map(this.program!.getSourceFiles(), sourceFile => {
const scriptInfo = this.projectService.getScriptInfoForPath(sourceFile.resolvedPath);
Debug.assert(!!scriptInfo, "getScriptInfo", () => `scriptInfo for a file '${sourceFile.fileName}' Path: '${sourceFile.path}' / '${sourceFile.resolvedPath}' is missing.`);
return scriptInfo!;
@@ -749,7 +749,7 @@ namespace ts.server {
}
containsScriptInfo(info: ScriptInfo): boolean {
return this.isRoot(info) || (this.program && this.program.getSourceFileByPath(info.path) !== undefined);
return this.isRoot(info) || (!!this.program && this.program.getSourceFileByPath(info.path) !== undefined);
}
containsFile(filename: NormalizedPath, requireOpen?: boolean): boolean {
@@ -845,7 +845,7 @@ namespace ts.server {
// (can reuse cached imports for files that were not changed)
// 4. compilation settings were changed in the way that might affect module resolution - drop all caches and collect all data from the scratch
if (hasNewProgram || changedFiles.length) {
this.lastCachedUnresolvedImportsList = getUnresolvedImports(this.program, this.cachedUnresolvedImportsPerFile);
this.lastCachedUnresolvedImportsList = getUnresolvedImports(this.program!, this.cachedUnresolvedImportsPerFile);
}
this.projectService.typingsCache.enqueueInstallTypingsForProject(this, this.lastCachedUnresolvedImportsList, hasAddedorRemovedFiles);
@@ -872,7 +872,7 @@ namespace ts.server {
}
/* @internal */
getCurrentProgram() {
getCurrentProgram(): Program | undefined {
return this.program;
}
@@ -911,7 +911,7 @@ namespace ts.server {
}
oldProgram.forEachResolvedProjectReference((resolvedProjectReference, resolvedProjectReferencePath) => {
if (resolvedProjectReference && !this.program.getResolvedProjectReferenceByPath(resolvedProjectReferencePath)) {
if (resolvedProjectReference && !this.program!.getResolvedProjectReferenceByPath(resolvedProjectReferencePath)) {
this.detachScriptInfoFromProject(resolvedProjectReference.sourceFile.fileName);
}
});
@@ -967,8 +967,8 @@ namespace ts.server {
this.getCachedDirectoryStructureHost().addOrDeleteFile(fileName, missingFilePath, eventKind);
}
if (eventKind === FileWatcherEventKind.Created && this.missingFilesMap.has(missingFilePath)) {
this.missingFilesMap.delete(missingFilePath);
if (eventKind === FileWatcherEventKind.Created && this.missingFilesMap!.has(missingFilePath)) {
this.missingFilesMap!.delete(missingFilePath);
fileWatcher.close();
// When a missing file is created, we should update the graph.
@@ -983,7 +983,7 @@ namespace ts.server {
}
private isWatchedMissingFile(path: Path) {
return this.missingFilesMap && this.missingFilesMap.has(path);
return !!this.missingFilesMap && this.missingFilesMap.has(path);
}
getScriptInfoForNormalizedPath(fileName: NormalizedPath): ScriptInfo | undefined {
@@ -1344,14 +1344,14 @@ namespace ts.server {
* Otherwise it will create an InferredProject.
*/
export class ConfiguredProject extends Project {
private typeAcquisition: TypeAcquisition;
private typeAcquisition!: TypeAcquisition; // TODO: GH#18217
/* @internal */
configFileWatcher: FileWatcher | undefined;
private directoriesWatchedForWildcards: Map<WildcardDirectoryWatcher> | undefined;
readonly canonicalConfigFilePath: NormalizedPath;
/* @internal */
pendingReload: ConfigFileProgramReloadLevel;
pendingReload: ConfigFileProgramReloadLevel | undefined;
/* @internal */
pendingReloadReason: string | undefined;
@@ -1359,7 +1359,7 @@ namespace ts.server {
configFileSpecs: ConfigFileSpecs | undefined;
/*@internal*/
canConfigFileJsonReportNoInputFiles: boolean;
canConfigFileJsonReportNoInputFiles = false;
/** Ref count to the project when opened from external project */
private externalProjectRefCount = 0;
@@ -1590,7 +1590,7 @@ namespace ts.server {
*/
export class ExternalProject extends Project {
excludedFiles: ReadonlyArray<NormalizedPath> = [];
private typeAcquisition: TypeAcquisition;
private typeAcquisition!: TypeAcquisition; // TODO: GH#18217
/*@internal*/
constructor(public externalProjectName: string,
projectService: ProjectService,

View File

@@ -36,15 +36,15 @@ namespace ts.server {
/**
* True if the text is for the file thats open in the editor
*/
public isOpen: boolean;
public isOpen = false;
/**
* True if the text present is the text from the file on the disk
*/
private ownFileText: boolean;
private ownFileText = false;
/**
* True when reloading contents of file from the disk is pending
*/
private pendingReloadFromDisk: boolean;
private pendingReloadFromDisk = false;
constructor(private readonly host: ServerHost, private readonly fileName: NormalizedPath, initialVersion: ScriptInfoVersion | undefined, private readonly info: ScriptInfo) {
this.version = initialVersion || { svc: 0, text: 0 };
@@ -279,7 +279,7 @@ namespace ts.server {
private realpath: Path | undefined;
/*@internal*/
cacheSourceFile: DocumentRegistrySourceFileCache;
cacheSourceFile: DocumentRegistrySourceFileCache | undefined;
/*@internal*/
mTime?: number;

View File

@@ -41,11 +41,11 @@ namespace ts.server {
// path to start of range
private readonly startPath: LineCollection[];
private readonly endBranch: LineCollection[] = [];
private branchNode: LineNode;
private branchNode: LineNode | undefined;
// path to current node
private readonly stack: LineNode[];
private state = CharRangeSection.Entire;
private lineCollectionAtBranch: LineCollection;
private lineCollectionAtBranch: LineCollection | undefined;
private initialText = "";
private trailingText = "";
@@ -383,7 +383,7 @@ namespace ts.server {
}
export class LineIndex {
root: LineNode;
root!: LineNode;
// set this to true to check each edit for accuracy
checkEdits = false;

View File

@@ -516,7 +516,7 @@ namespace ts.server {
protected projectService: ProjectService;
private changeSeq = 0;
private currentRequestId: number;
private currentRequestId!: number;
private errorCheck: MultistepOperation;
protected host: ServerHost;