Fix many no-object-literal-type-assertion lint errors (#17278)

* Fix many no-object-literal-type-assertion lint errors

* Simple fixes

* Use a union for FlowNode

* PR feedback and remove remaining `id()` uses

* Use a union for CodeBlock

* Discriminate CodeBlock by CodeBlockKind
This commit is contained in:
Andy
2017-08-10 12:52:15 -07:00
committed by GitHub
parent fe3a05e89a
commit 08fbcd8b80
17 changed files with 140 additions and 148 deletions

View File

@@ -564,7 +564,7 @@ namespace Harness {
}
export let listFiles: typeof IO.listFiles = (path, spec?, options?) => {
options = options || <{ recursive?: boolean; }>{};
options = options || {};
function filesInFolder(folder: string): string[] {
let paths: string[] = [];

View File

@@ -426,12 +426,12 @@ class ProjectRunner extends RunnerBase {
compilerResult.program ?
ts.filter(compilerResult.program.getSourceFiles(), sourceFile => !Harness.isDefaultLibraryFile(sourceFile.fileName)) :
[]),
sourceFile => <Harness.Compiler.TestFile>{
(sourceFile): Harness.Compiler.TestFile => ({
unitName: ts.isRootedDiskPath(sourceFile.fileName) ?
RunnerBase.removeFullPaths(sourceFile.fileName) :
sourceFile.fileName,
content: sourceFile.text
});
}));
return Harness.Compiler.getErrorBaseline(inputFiles, compilerResult.errors);
}

View File

@@ -518,18 +518,20 @@ namespace ts.projectSystem {
};
const host = createServerHost([f], { newLine });
const session = createSession(host);
session.executeCommand(<server.protocol.OpenRequest>{
const openRequest: server.protocol.OpenRequest = {
seq: 1,
type: "request",
command: "open",
command: server.protocol.CommandTypes.Open,
arguments: { file: f.path }
});
session.executeCommand(<server.protocol.CompileOnSaveEmitFileRequest>{
};
session.executeCommand(openRequest);
const emitFileRequest: server.protocol.CompileOnSaveEmitFileRequest = {
seq: 2,
type: "request",
command: "compileOnSaveEmitFile",
command: server.protocol.CommandTypes.CompileOnSaveEmitFile,
arguments: { file: f.path }
});
};
session.executeCommand(emitFileRequest);
const emitOutput = host.readFile(path + ts.Extension.Js);
assert.equal(emitOutput, f.content + newLine, "content of emit output should be identical with the input + newline");
}

View File

@@ -67,14 +67,14 @@ namespace ts {
}
}, "tsconfig.json",
{
compilerOptions: <CompilerOptions>{
compilerOptions: {
module: ModuleKind.CommonJS,
target: ScriptTarget.ES5,
noImplicitAny: false,
sourceMap: false,
lib: ["lib.es5.d.ts", "lib.es2015.core.d.ts", "lib.es2015.symbol.d.ts"]
},
errors: <Diagnostic[]>[]
errors: []
}
);
});
@@ -92,7 +92,7 @@ namespace ts {
}
}, "tsconfig.json",
{
compilerOptions: <CompilerOptions>{
compilerOptions: {
module: ModuleKind.CommonJS,
target: ScriptTarget.ES5,
noImplicitAny: false,
@@ -100,7 +100,7 @@ namespace ts {
allowJs: false,
lib: ["lib.es5.d.ts", "lib.es2015.core.d.ts", "lib.es2015.symbol.d.ts"]
},
errors: <Diagnostic[]>[]
errors: []
}
);
});
@@ -117,7 +117,7 @@ namespace ts {
}
}, "tsconfig.json",
{
compilerOptions: <CompilerOptions>{
compilerOptions: {
module: ModuleKind.CommonJS,
target: ScriptTarget.ES5,
noImplicitAny: false,
@@ -146,7 +146,7 @@ namespace ts {
}
}, "tsconfig.json",
{
compilerOptions: <CompilerOptions>{
compilerOptions: {
target: ScriptTarget.ES5,
noImplicitAny: false,
sourceMap: false,
@@ -174,7 +174,7 @@ namespace ts {
}
}, "tsconfig.json",
{
compilerOptions: <CompilerOptions>{
compilerOptions: {
target: ScriptTarget.ES5,
noImplicitAny: false,
sourceMap: false,
@@ -201,7 +201,7 @@ namespace ts {
}
}, "tsconfig.json",
{
compilerOptions: <CompilerOptions>{
compilerOptions: {
noImplicitAny: false,
sourceMap: false,
},
@@ -227,7 +227,7 @@ namespace ts {
}
}, "tsconfig.json",
{
compilerOptions: <CompilerOptions>{
compilerOptions: {
noImplicitAny: false,
sourceMap: false,
},
@@ -255,7 +255,7 @@ namespace ts {
}
}, "tsconfig.json",
{
compilerOptions: <CompilerOptions>{
compilerOptions: {
module: ModuleKind.CommonJS,
target: ScriptTarget.ES5,
noImplicitAny: false,
@@ -286,7 +286,7 @@ namespace ts {
}
}, "tsconfig.json",
{
compilerOptions: <CompilerOptions>{
compilerOptions: {
module: ModuleKind.CommonJS,
target: ScriptTarget.ES5,
noImplicitAny: false,
@@ -317,7 +317,7 @@ namespace ts {
}
}, "tsconfig.json",
{
compilerOptions: <CompilerOptions>{
compilerOptions: {
module: ModuleKind.CommonJS,
target: ScriptTarget.ES5,
noImplicitAny: false,
@@ -348,7 +348,7 @@ namespace ts {
}
}, "tsconfig.json",
{
compilerOptions: <CompilerOptions>{
compilerOptions: {
module: ModuleKind.CommonJS,
target: ScriptTarget.ES5,
noImplicitAny: false,
@@ -379,7 +379,7 @@ namespace ts {
}
}, "tsconfig.json",
{
compilerOptions: <CompilerOptions>{
compilerOptions: {
module: ModuleKind.CommonJS,
target: ScriptTarget.ES5,
noImplicitAny: false,
@@ -415,8 +415,8 @@ namespace ts {
it("Convert default tsconfig.json to compiler-options ", () => {
assertCompilerOptions({}, "tsconfig.json",
{
compilerOptions: {} as CompilerOptions,
errors: <Diagnostic[]>[]
compilerOptions: {},
errors: []
}
);
});
@@ -434,7 +434,7 @@ namespace ts {
}
}, "jsconfig.json",
{
compilerOptions: <CompilerOptions>{
compilerOptions: {
allowJs: true,
maxNodeModuleJsDepth: 2,
allowSyntheticDefaultImports: true,
@@ -445,7 +445,7 @@ namespace ts {
sourceMap: false,
lib: ["lib.es5.d.ts", "lib.es2015.core.d.ts", "lib.es2015.symbol.d.ts"]
},
errors: <Diagnostic[]>[]
errors: []
}
);
});
@@ -463,7 +463,7 @@ namespace ts {
}
}, "jsconfig.json",
{
compilerOptions: <CompilerOptions>{
compilerOptions: {
allowJs: false,
maxNodeModuleJsDepth: 2,
allowSyntheticDefaultImports: true,
@@ -474,7 +474,7 @@ namespace ts {
sourceMap: false,
lib: ["lib.es5.d.ts", "lib.es2015.core.d.ts", "lib.es2015.symbol.d.ts"]
},
errors: <Diagnostic[]>[]
errors: []
}
);
});
@@ -516,7 +516,7 @@ namespace ts {
allowSyntheticDefaultImports: true,
skipLibCheck: true
},
errors: <Diagnostic[]>[]
errors: []
}
);
});

View File

@@ -110,23 +110,21 @@ namespace ts {
}
{
const actual = ts.parseJsonConfigFileContent(json, host, basePath, existingOptions, configFileName, resolutionStack);
expected.errors = map(expected.errors, error => {
return <Diagnostic>{
category: error.category,
code: error.code,
file: undefined,
length: undefined,
messageText: error.messageText,
start: undefined,
};
});
expected.errors = expected.errors.map<Diagnostic>(error => ({
category: error.category,
code: error.code,
file: undefined,
length: undefined,
messageText: error.messageText,
start: undefined,
}));
assertParsed(actual, expected);
}
}
function createDiagnosticForConfigFile(json: any, start: number, length: number, diagnosticMessage: DiagnosticMessage, arg0: string) {
const text = JSON.stringify(json);
const file = <SourceFile>{
const file = <SourceFile>{ // tslint:disable-line no-object-literal-type-assertion
fileName: caseInsensitiveTsconfigPath,
kind: SyntaxKind.SourceFile,
text

View File

@@ -81,14 +81,15 @@ namespace ts.server {
session.executeCommand(req);
expect(lastSent).to.deep.equal(<protocol.Response>{
const expected: protocol.Response = {
command: CommandNames.Unknown,
type: "response",
seq: 0,
message: "Unrecognized JSON command: foobar",
request_seq: 0,
success: false
});
};
expect(lastSent).to.deep.equal(expected);
});
it("should return a tuple containing the response and if a response is required on success", () => {
const req: protocol.ConfigureRequest = {

View File

@@ -935,25 +935,26 @@ namespace ts.projectSystem {
import * as cmd from "commander
`
};
session.executeCommand(<server.protocol.OpenRequest>{
const openRequest: server.protocol.OpenRequest = {
seq: 1,
type: "request",
command: "open",
command: server.protocol.CommandTypes.Open,
arguments: {
file: f.path,
fileContent: f.content
}
});
};
session.executeCommand(openRequest);
const projectService = session.getProjectService();
checkNumberOfProjects(projectService, { inferredProjects: 1 });
const proj = projectService.inferredProjects[0];
const version1 = proj.getCachedUnresolvedImportsPerFile_TestOnly().getVersion();
// make a change that should not affect the structure of the program
session.executeCommand(<server.protocol.ChangeRequest>{
const changeRequest: server.protocol.ChangeRequest = {
seq: 2,
type: "request",
command: "change",
command: server.protocol.CommandTypes.Change,
arguments: {
file: f.path,
insertString: "\nlet x = 1;",
@@ -962,7 +963,8 @@ namespace ts.projectSystem {
endLine: 2,
endOffset: 0
}
});
};
session.executeCommand(changeRequest);
host.checkTimeoutQueueLength(1);
host.runQueuedTimeoutCallbacks();
const version2 = proj.getCachedUnresolvedImportsPerFile_TestOnly().getVersion();