mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-11-18 20:11:14 +00:00
Enable --strictPropertyInitialization (#27558)
* Enable --strictPropertyInitialization * Code review
This commit is contained in:
26 files changed
+168
-165
No files matched your search
@@ -13,7 +13,7 @@ class CompilerBaselineRunner extends RunnerBase {
|
||||
private testSuiteName: TestRunnerKind;
|
||||
private emit: boolean;
|
||||
|
||||
public options: string;
|
||||
public options: string | undefined;
|
||||
|
||||
constructor(public testType: CompilerTestType) {
|
||||
super();
|
||||
|
||||
@@ -21,6 +21,8 @@ class FourSlashRunner extends RunnerBase {
|
||||
this.basePath = "tests/cases/fourslash/server";
|
||||
this.testSuiteName = "fourslash-server";
|
||||
break;
|
||||
default:
|
||||
throw ts.Debug.assertNever(testType);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,9 +28,9 @@ namespace Harness.Parallel.Host {
|
||||
let totalCost = 0;
|
||||
|
||||
class RemoteSuite extends Mocha.Suite {
|
||||
suites: RemoteSuite[];
|
||||
suites!: RemoteSuite[];
|
||||
suiteMap = ts.createMap<RemoteSuite>();
|
||||
tests: RemoteTest[];
|
||||
tests!: RemoteTest[];
|
||||
constructor(title: string) {
|
||||
super(title);
|
||||
this.pending = false;
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace project {
|
||||
|
||||
class ProjectCompilerHost extends fakes.CompilerHost {
|
||||
private _testCase: ProjectRunnerTestCase & ts.CompilerOptions;
|
||||
private _projectParseConfigHost: ProjectParseConfigHost;
|
||||
private _projectParseConfigHost: ProjectParseConfigHost | undefined;
|
||||
|
||||
constructor(sys: fakes.System | vfs.FileSystem, compilerOptions: ts.CompilerOptions, _testCaseJustName: string, testCase: ProjectRunnerTestCase & ts.CompilerOptions, _moduleKind: ts.ModuleKind) {
|
||||
super(sys, compilerOptions);
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
export class SourceText implements IScriptSnapshot {
|
||||
private fullText: string;
|
||||
private fullText: string | undefined;
|
||||
|
||||
constructor(private references: string,
|
||||
private importsAndExports: string,
|
||||
|
||||
@@ -437,7 +437,7 @@ namespace ts.server {
|
||||
|
||||
const command = "testhandler";
|
||||
class TestSession extends Session {
|
||||
lastSent: protocol.Message;
|
||||
lastSent: protocol.Message | undefined;
|
||||
private exceptionRaisingHandler(_request: protocol.Request): { response?: any, responseRequired: boolean } {
|
||||
f1();
|
||||
return Debug.fail(); // unreachable, throw to make compiler happy
|
||||
@@ -491,7 +491,7 @@ namespace ts.server {
|
||||
|
||||
describe("how Session is extendable via subclassing", () => {
|
||||
class TestSession extends Session {
|
||||
lastSent: protocol.Message;
|
||||
lastSent: protocol.Message | undefined;
|
||||
customHandler = "testhandler";
|
||||
constructor() {
|
||||
super({
|
||||
@@ -610,7 +610,7 @@ namespace ts.server {
|
||||
}
|
||||
|
||||
class InProcClient {
|
||||
private server: InProcSession;
|
||||
private server: InProcSession | undefined;
|
||||
private seq = 0;
|
||||
private callbacks: ((resp: protocol.Response) => void)[] = [];
|
||||
private eventHandlers = createMap<(args: any) => void>();
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace ts.projectSystem {
|
||||
}
|
||||
|
||||
export class TestTypingsInstaller extends TI.TypingsInstaller implements server.ITypingsInstaller {
|
||||
protected projectService: server.ProjectService;
|
||||
protected projectService!: server.ProjectService;
|
||||
constructor(
|
||||
readonly globalTypingsCacheLocation: string,
|
||||
throttleLimit: number,
|
||||
@@ -282,7 +282,7 @@ namespace ts.projectSystem {
|
||||
class TestSession extends server.Session {
|
||||
private seq = 0;
|
||||
public events: protocol.Event[] = [];
|
||||
public host: TestServerHost;
|
||||
public host!: TestServerHost;
|
||||
|
||||
getProjectService() {
|
||||
return this.projectService;
|
||||
@@ -9396,16 +9396,16 @@ export const x = 10;`
|
||||
const project = getProject(service);
|
||||
|
||||
const moduleInfo = service.getScriptInfo(moduleFile.path)!;
|
||||
const sourceFile = moduleInfo.cacheSourceFile.sourceFile;
|
||||
const sourceFile = moduleInfo.cacheSourceFile!.sourceFile;
|
||||
assert.equal(project.getSourceFile(moduleInfo.path), sourceFile);
|
||||
|
||||
// edit file
|
||||
changeFileToNotImportModule(service);
|
||||
assert.equal(moduleInfo.cacheSourceFile.sourceFile, sourceFile);
|
||||
assert.equal(moduleInfo.cacheSourceFile!.sourceFile, sourceFile);
|
||||
|
||||
// write content back
|
||||
changeFileToImportModule(service);
|
||||
assert.equal(moduleInfo.cacheSourceFile.sourceFile, sourceFile);
|
||||
assert.equal(moduleInfo.cacheSourceFile!.sourceFile, sourceFile);
|
||||
assert.equal(project.getSourceFile(moduleInfo.path), sourceFile);
|
||||
});
|
||||
|
||||
@@ -9414,21 +9414,21 @@ export const x = 10;`
|
||||
const project = getProject(service);
|
||||
|
||||
const moduleInfo = service.getScriptInfo(moduleFile.path)!;
|
||||
const sourceFile = moduleInfo.cacheSourceFile.sourceFile;
|
||||
const sourceFile = moduleInfo.cacheSourceFile!.sourceFile;
|
||||
assert.equal(project.getSourceFile(moduleInfo.path), sourceFile);
|
||||
|
||||
// edit file
|
||||
changeFileToNotImportModule(service);
|
||||
assert.equal(moduleInfo.cacheSourceFile.sourceFile, sourceFile);
|
||||
assert.equal(moduleInfo.cacheSourceFile!.sourceFile, sourceFile);
|
||||
|
||||
const updatedModuleContent = moduleFile.content + "\nexport const b: number;";
|
||||
host.writeFile(moduleFile.path, updatedModuleContent);
|
||||
|
||||
// write content back
|
||||
changeFileToImportModule(service);
|
||||
assert.notEqual(moduleInfo.cacheSourceFile.sourceFile, sourceFile);
|
||||
assert.equal(project.getSourceFile(moduleInfo.path), moduleInfo.cacheSourceFile.sourceFile);
|
||||
assert.equal(moduleInfo.cacheSourceFile.sourceFile.text, updatedModuleContent);
|
||||
assert.notEqual(moduleInfo.cacheSourceFile!.sourceFile, sourceFile);
|
||||
assert.equal(project.getSourceFile(moduleInfo.path), moduleInfo.cacheSourceFile!.sourceFile);
|
||||
assert.equal(moduleInfo.cacheSourceFile!.sourceFile.text, updatedModuleContent);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -9457,7 +9457,7 @@ export const x = 10;`
|
||||
// large file for non ts file should be empty and for ts file should have content
|
||||
const service = session.getProjectService();
|
||||
const info = service.getScriptInfo(largeFile.path)!;
|
||||
assert.equal(info.cacheSourceFile.sourceFile.text, useLargeTsFile ? largeFile.content : "");
|
||||
assert.equal(info.cacheSourceFile!.sourceFile.text, useLargeTsFile ? largeFile.content : "");
|
||||
|
||||
assert.deepEqual(largeFileReferencedEvents, useLargeTsFile ? emptyArray : [{
|
||||
eventName: server.LargeFileReferencedEvent,
|
||||
@@ -10970,7 +10970,7 @@ fn5();`
|
||||
function checkDeclarationFiles(file: File, session: TestSession, expectedFiles: ReadonlyArray<File>): void {
|
||||
openFilesForSession([file], session);
|
||||
const project = Debug.assertDefined(session.getProjectService().getDefaultProjectForFile(file.path as server.NormalizedPath, /*ensureProject*/ false));
|
||||
const program = project.getCurrentProgram();
|
||||
const program = project.getCurrentProgram()!;
|
||||
const output = getFileEmitOutput(program, Debug.assertDefined(program.getSourceFile(file.path)), /*emitOnlyDtsFiles*/ true);
|
||||
closeFilesForSession([file], session);
|
||||
|
||||
|
||||
Reference in new issue
Block a user