Skip to content

Commit 7553b3b

Browse files
author
andy-ms
committed
Finish applying no-object-literal-type-assertion lint rule
1 parent 541920e commit 7553b3b

File tree

9 files changed

+124
-101
lines changed

9 files changed

+124
-101
lines changed

src/compiler/checker.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,8 +1862,10 @@ namespace ts {
18621862
target.set(id, sourceSymbol);
18631863
if (lookupTable && exportNode) {
18641864
lookupTable.set(id, {
1865-
specifierText: getTextOfNode(exportNode.moduleSpecifier)
1866-
} as ExportCollisionTracker);
1865+
specifierText: getTextOfNode(exportNode.moduleSpecifier),
1866+
// TODO: GH#18217: (exportsWithDuplicate was not present)
1867+
exportsWithDuplicate: undefined,
1868+
});
18671869
}
18681870
}
18691871
else if (lookupTable && exportNode && targetSymbol && resolveSymbol(targetSymbol) !== resolveSymbol(sourceSymbol)) {
@@ -6298,18 +6300,20 @@ namespace ts {
62986300
function createTypePredicateFromTypePredicateNode(node: TypePredicateNode): IdentifierTypePredicate | ThisTypePredicate {
62996301
const { parameterName } = node;
63006302
if (parameterName.kind === SyntaxKind.Identifier) {
6301-
return {
6303+
const result: IdentifierTypePredicate = {
63026304
kind: TypePredicateKind.Identifier,
6303-
parameterName: parameterName ? parameterName.escapedText : undefined,
6305+
parameterName: parameterName ? parameterName.text : undefined,
63046306
parameterIndex: parameterName ? getTypePredicateParameterIndex((node.parent as SignatureDeclaration).parameters, parameterName) : undefined,
6305-
type: getTypeFromTypeNode(node.type)
6306-
} as IdentifierTypePredicate;
6307+
type: getTypeFromTypeNode(node.type),
6308+
};
6309+
return result;
63076310
}
63086311
else {
6309-
return {
6312+
const result: ThisTypePredicate = {
63106313
kind: TypePredicateKind.This,
63116314
type: getTypeFromTypeNode(node.type)
63126315
};
6316+
return result;
63136317
}
63146318
}
63156319

src/compiler/commandLineParser.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,10 @@ namespace ts {
907907
*/
908908
export function readJsonConfigFile(fileName: string, readFile: (path: string) => string | undefined): JsonSourceFile {
909909
const textOrDiagnostic = tryReadFile(fileName, readFile);
910-
return typeof textOrDiagnostic === "string" ? parseJsonText(fileName, textOrDiagnostic) : <JsonSourceFile>{ parseDiagnostics: [textOrDiagnostic] };
910+
return typeof textOrDiagnostic === "string"
911+
? parseJsonText(fileName, textOrDiagnostic)
912+
// tslint:disable-next-line no-object-literal-type-assertion (TODO:GH#18217)
913+
: <JsonSourceFile>{ parseDiagnostics: [textOrDiagnostic] };
911914
}
912915

913916
function tryReadFile(fileName: string, readFile: (path: string) => string | undefined): string | Diagnostic {

src/harness/unittests/session.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@ namespace ts.server {
148148
}
149149
};
150150
session.onMessage(JSON.stringify(setOptionsRequest));
151-
assert.deepEqual(
151+
assert.deepEqual<CompilerOptions>(
152152
session.getProjectService().getCompilerOptionsForInferredProjects(),
153-
<CompilerOptions>{
153+
{
154154
module: ModuleKind.System,
155155
target: ScriptTarget.ES5,
156156
jsx: JsxEmit.React,
@@ -284,7 +284,7 @@ namespace ts.server {
284284

285285
session.onMessage(JSON.stringify(req));
286286

287-
expect(lastSent).to.deep.equal(<protocol.ConfigureResponse>{
287+
assert.deepEqual<protocol.ConfigureResponse>(lastSent as protocol.ConfigureResponse, {
288288
command: CommandNames.Configure,
289289
type: "response",
290290
success: true,

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 93 additions & 84 deletions
Large diffs are not rendered by default.

src/server/editorServices.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,7 @@ namespace ts.server {
10391039

10401040
const result = parseJsonText(configFilename, configFileContent);
10411041
if (!result.endOfFileToken) {
1042+
// tslint:disable-next-line no-object-literal-type-assertion (TODO: GH#18217)
10421043
result.endOfFileToken = <EndOfFileToken>{ kind: SyntaxKind.EndOfFileToken };
10431044
}
10441045
const errors = result.parseDiagnostics;

src/server/project.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,8 @@ namespace ts.server {
10031003
if (options.plugins && options.plugins.some(p => p.name === globalPluginName)) continue;
10041004

10051005
// Provide global: true so plugins can detect why they can't find their config
1006+
// TODO: Pluginimport has no `global` property!
1007+
// tslint:disable-next-line no-object-literal-type-assertion (TODO: GH#18217)
10061008
this.enablePlugin({ name: globalPluginName, global: true } as PluginImport, searchPaths);
10071009
}
10081010
}

src/server/session.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ namespace ts.server {
568568
}
569569

570570
private convertToDiagnosticsWithLinePosition(diagnostics: ReadonlyArray<Diagnostic>, scriptInfo: ScriptInfo): protocol.DiagnosticWithLinePosition[] {
571-
return diagnostics.map(d => <protocol.DiagnosticWithLinePosition>{
571+
return diagnostics.map<protocol.DiagnosticWithLinePosition>(d => ({
572572
message: flattenDiagnosticMessageText(d.messageText, this.host.newLine),
573573
start: d.start,
574574
length: d.length,
@@ -577,7 +577,7 @@ namespace ts.server {
577577
source: d.source,
578578
startLocation: scriptInfo && scriptInfo.positionToLineOffset(d.start),
579579
endLocation: scriptInfo && scriptInfo.positionToLineOffset(d.start + d.length)
580-
});
580+
}));
581581
}
582582

583583
private getDiagnosticsWorker(
@@ -1952,7 +1952,7 @@ namespace ts.server {
19521952
}
19531953
}
19541954

1955-
public executeCommand(request: protocol.Request): { response?: any, responseRequired?: boolean } {
1955+
public executeCommand<T extends protocol.Request>(request: T): { response?: any, responseRequired?: boolean } {
19561956
const handler = this.handlers.get(request.command);
19571957
if (handler) {
19581958
return this.executeWithRequestId(request.seq, () => handler(request));

src/server/typingsInstaller/typingsInstaller.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,15 @@ namespace ts.server.typingsInstaller {
328328
this.installRunCount++;
329329

330330
// send progress event
331-
this.sendResponse(<BeginInstallTypes>{
331+
const response: BeginInstallTypes = {
332332
kind: EventBeginInstallTypes,
333333
eventId: requestId,
334334
typingsInstallerVersion: ts.version, // qualified explicitly to prevent occasional shadowing
335-
projectName: req.projectName
336-
});
335+
projectName: req.projectName,
336+
// TODO: GH#18217 (property was not present)
337+
packagesToInstall: undefined
338+
};
339+
this.sendResponse(response);
337340

338341
const scopedTypings = filteredTypings.map(typingsName);
339342
this.installTypingsAsync(requestId, scopedTypings, cachePath, ok => {

tslint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"no-inferrable-types": true,
2424
"no-internal-module": true,
2525
"no-null-keyword": true,
26+
"no-object-literal-type-assertion": true,
2627
"no-switch-case-fall-through": true,
2728
"no-trailing-whitespace": [true, "ignore-template-strings"],
2829
"no-type-assertion-whitespace": true,

0 commit comments

Comments
 (0)