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

@ -806,11 +806,7 @@ namespace ts {
return antecedent;
}
setFlowNodeReferenced(antecedent);
return <FlowCondition>{
flags,
expression,
antecedent
};
return { flags, expression, antecedent };
}
function createFlowSwitchClause(antecedent: FlowNode, switchStatement: SwitchStatement, clauseStart: number, clauseEnd: number): FlowNode {
@ -818,31 +814,18 @@ namespace ts {
return antecedent;
}
setFlowNodeReferenced(antecedent);
return <FlowSwitchClause>{
flags: FlowFlags.SwitchClause,
switchStatement,
clauseStart,
clauseEnd,
antecedent
};
return { flags: FlowFlags.SwitchClause, switchStatement, clauseStart, clauseEnd, antecedent };
}
function createFlowAssignment(antecedent: FlowNode, node: Expression | VariableDeclaration | BindingElement): FlowNode {
setFlowNodeReferenced(antecedent);
return <FlowAssignment>{
flags: FlowFlags.Assignment,
antecedent,
node
};
return { flags: FlowFlags.Assignment, antecedent, node };
}
function createFlowArrayMutation(antecedent: FlowNode, node: CallExpression | BinaryExpression): FlowNode {
setFlowNodeReferenced(antecedent);
return <FlowArrayMutation>{
flags: FlowFlags.ArrayMutation,
antecedent,
node
};
const res: FlowArrayMutation = { flags: FlowFlags.ArrayMutation, antecedent, node };
return res;
}
function finishFlowLabel(flow: FlowLabel): FlowNode {

View File

@ -2172,7 +2172,7 @@ namespace ts {
if (accessibleSymbolChain) {
const hasAccessibleDeclarations = hasVisibleDeclarations(accessibleSymbolChain[0], shouldComputeAliasesToMakeVisible);
if (!hasAccessibleDeclarations) {
return <SymbolAccessibilityResult>{
return {
accessibility: SymbolAccessibility.NotAccessible,
errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning),
errorModuleName: symbol !== initialSymbol ? symbolToString(symbol, enclosingDeclaration, SymbolFlags.Namespace) : undefined,
@ -2294,7 +2294,7 @@ namespace ts {
const symbol = resolveName(enclosingDeclaration, firstIdentifier.escapedText, meaning, /*nodeNotFoundErrorMessage*/ undefined, /*nameArg*/ undefined);
// Verify if the symbol is accessible
return (symbol && hasVisibleDeclarations(symbol, /*shouldComputeAliasToMakeVisible*/ true)) || <SymbolVisibilityResult>{
return (symbol && hasVisibleDeclarations(symbol, /*shouldComputeAliasToMakeVisible*/ true)) || {
accessibility: SymbolAccessibility.NotAccessible,
errorSymbolName: getTextOfNode(firstIdentifier),
errorNode: firstIdentifier
@ -6300,7 +6300,7 @@ namespace ts {
return {
kind: TypePredicateKind.This,
type: getTypeFromTypeNode(node.type)
} as ThisTypePredicate;
};
}
}
@ -8109,13 +8109,13 @@ namespace ts {
parameterName: predicate.parameterName,
parameterIndex: predicate.parameterIndex,
type: instantiateType(predicate.type, mapper)
} as IdentifierTypePredicate;
};
}
else {
return {
kind: TypePredicateKind.This,
type: instantiateType(predicate.type, mapper)
} as ThisTypePredicate;
};
}
}

View File

@ -1195,7 +1195,9 @@ namespace ts {
if (!(getEmitFlags(node) & EmitFlags.NoIndentation)) {
const dotRangeStart = node.expression.end;
const dotRangeEnd = skipTrivia(currentSourceFile.text, node.expression.end) + 1;
const dotToken = <Node>{ kind: SyntaxKind.DotToken, pos: dotRangeStart, end: dotRangeEnd };
const dotToken = createToken(SyntaxKind.DotToken);
dotToken.pos = dotRangeStart;
dotToken.end = dotRangeEnd;
indentBeforeDot = needsIndentation(node, node.expression, dotToken);
indentAfterDot = needsIndentation(node, dotToken, node.name);
}

View File

@ -2586,7 +2586,7 @@ namespace ts {
}
export function addSyntheticLeadingComment<T extends Node>(node: T, kind: SyntaxKind.SingleLineCommentTrivia | SyntaxKind.MultiLineCommentTrivia, text: string, hasTrailingNewLine?: boolean) {
return setSyntheticLeadingComments(node, append(getSyntheticLeadingComments(node), <SynthesizedComment>{ kind, pos: -1, end: -1, hasTrailingNewLine, text }));
return setSyntheticLeadingComments(node, append<SynthesizedComment>(getSyntheticLeadingComments(node), { kind, pos: -1, end: -1, hasTrailingNewLine, text }));
}
export function getSyntheticTrailingComments(node: Node): SynthesizedComment[] | undefined {
@ -2600,7 +2600,7 @@ namespace ts {
}
export function addSyntheticTrailingComment<T extends Node>(node: T, kind: SyntaxKind.SingleLineCommentTrivia | SyntaxKind.MultiLineCommentTrivia, text: string, hasTrailingNewLine?: boolean) {
return setSyntheticTrailingComments(node, append(getSyntheticTrailingComments(node), <SynthesizedComment>{ kind, pos: -1, end: -1, hasTrailingNewLine, text }));
return setSyntheticTrailingComments(node, append<SynthesizedComment>(getSyntheticTrailingComments(node), { kind, pos: -1, end: -1, hasTrailingNewLine, text }));
}
/**

View File

@ -6169,7 +6169,7 @@ namespace ts {
export function parseIsolatedJSDocComment(content: string, start: number, length: number): { jsDoc: JSDoc, diagnostics: Diagnostic[] } | undefined {
initializeState(content, ScriptTarget.Latest, /*_syntaxCursor:*/ undefined, ScriptKind.JS);
sourceFile = <SourceFile>{ languageVariant: LanguageVariant.Standard, text: content };
sourceFile = <SourceFile>{ languageVariant: LanguageVariant.Standard, text: content }; // tslint:disable-line no-object-literal-type-assertion
const jsDoc = parseJSDocCommentWorker(start, length);
const diagnostics = parseDiagnostics;
clearState();

View File

@ -164,12 +164,11 @@ namespace ts {
}
// A generated code block
interface CodeBlock {
kind: CodeBlockKind;
}
type CodeBlock = | ExceptionBlock | LabeledBlock | SwitchBlock | LoopBlock | WithBlock;
// a generated exception block, used for 'try' statements
interface ExceptionBlock extends CodeBlock {
interface ExceptionBlock {
kind: CodeBlockKind.Exception;
state: ExceptionBlockState;
startLabel: Label;
catchVariable?: Identifier;
@ -179,27 +178,31 @@ namespace ts {
}
// A generated code that tracks the target for 'break' statements in a LabeledStatement.
interface LabeledBlock extends CodeBlock {
interface LabeledBlock {
kind: CodeBlockKind.Labeled;
labelText: string;
isScript: boolean;
breakLabel: Label;
}
// a generated block that tracks the target for 'break' statements in a 'switch' statement
interface SwitchBlock extends CodeBlock {
interface SwitchBlock {
kind: CodeBlockKind.Switch;
isScript: boolean;
breakLabel: Label;
}
// a generated block that tracks the targets for 'break' and 'continue' statements, used for iteration statements
interface LoopBlock extends CodeBlock {
interface LoopBlock {
kind: CodeBlockKind.Loop;
continueLabel: Label;
isScript: boolean;
breakLabel: Label;
}
// a generated block associated with a 'with' statement
interface WithBlock extends CodeBlock {
interface WithBlock {
kind: CodeBlockKind.With;
expression: Identifier;
startLabel: Label;
endLabel: Label;
@ -2070,7 +2073,7 @@ namespace ts {
const startLabel = defineLabel();
const endLabel = defineLabel();
markLabel(startLabel);
beginBlock(<WithBlock>{
beginBlock({
kind: CodeBlockKind.With,
expression,
startLabel,
@ -2087,10 +2090,6 @@ namespace ts {
markLabel(block.endLabel);
}
function isWithBlock(block: CodeBlock): block is WithBlock {
return block.kind === CodeBlockKind.With;
}
/**
* Begins a code block for a generated `try` statement.
*/
@ -2098,7 +2097,7 @@ namespace ts {
const startLabel = defineLabel();
const endLabel = defineLabel();
markLabel(startLabel);
beginBlock(<ExceptionBlock>{
beginBlock({
kind: CodeBlockKind.Exception,
state: ExceptionBlockState.Try,
startLabel,
@ -2188,10 +2187,6 @@ namespace ts {
exception.state = ExceptionBlockState.Done;
}
function isExceptionBlock(block: CodeBlock): block is ExceptionBlock {
return block.kind === CodeBlockKind.Exception;
}
/**
* Begins a code block that supports `break` or `continue` statements that are defined in
* the source tree and not from generated code.
@ -2199,7 +2194,7 @@ namespace ts {
* @param labelText Names from containing labeled statements.
*/
function beginScriptLoopBlock(): void {
beginBlock(<LoopBlock>{
beginBlock({
kind: CodeBlockKind.Loop,
isScript: true,
breakLabel: -1,
@ -2217,7 +2212,7 @@ namespace ts {
*/
function beginLoopBlock(continueLabel: Label): Label {
const breakLabel = defineLabel();
beginBlock(<LoopBlock>{
beginBlock({
kind: CodeBlockKind.Loop,
isScript: false,
breakLabel,
@ -2245,7 +2240,7 @@ namespace ts {
*
*/
function beginScriptSwitchBlock(): void {
beginBlock(<SwitchBlock>{
beginBlock({
kind: CodeBlockKind.Switch,
isScript: true,
breakLabel: -1
@ -2259,7 +2254,7 @@ namespace ts {
*/
function beginSwitchBlock(): Label {
const breakLabel = defineLabel();
beginBlock(<SwitchBlock>{
beginBlock({
kind: CodeBlockKind.Switch,
isScript: false,
breakLabel,
@ -2280,7 +2275,7 @@ namespace ts {
}
function beginScriptLabeledBlock(labelText: string) {
beginBlock(<LabeledBlock>{
beginBlock({
kind: CodeBlockKind.Labeled,
isScript: true,
labelText,
@ -2290,7 +2285,7 @@ namespace ts {
function beginLabeledBlock(labelText: string) {
const breakLabel = defineLabel();
beginBlock(<LabeledBlock>{
beginBlock({
kind: CodeBlockKind.Labeled,
isScript: false,
labelText,
@ -2878,34 +2873,37 @@ namespace ts {
for (; blockIndex < blockActions.length && blockOffsets[blockIndex] <= operationIndex; blockIndex++) {
const block = blocks[blockIndex];
const blockAction = blockActions[blockIndex];
if (isExceptionBlock(block)) {
if (blockAction === BlockAction.Open) {
if (!exceptionBlockStack) {
exceptionBlockStack = [];
}
switch (block.kind) {
case CodeBlockKind.Exception:
if (blockAction === BlockAction.Open) {
if (!exceptionBlockStack) {
exceptionBlockStack = [];
}
if (!statements) {
statements = [];
}
if (!statements) {
statements = [];
}
exceptionBlockStack.push(currentExceptionBlock);
currentExceptionBlock = block;
}
else if (blockAction === BlockAction.Close) {
currentExceptionBlock = exceptionBlockStack.pop();
}
}
else if (isWithBlock(block)) {
if (blockAction === BlockAction.Open) {
if (!withBlockStack) {
withBlockStack = [];
exceptionBlockStack.push(currentExceptionBlock);
currentExceptionBlock = block;
}
else if (blockAction === BlockAction.Close) {
currentExceptionBlock = exceptionBlockStack.pop();
}
break;
case CodeBlockKind.With:
if (blockAction === BlockAction.Open) {
if (!withBlockStack) {
withBlockStack = [];
}
withBlockStack.push(block);
}
else if (blockAction === BlockAction.Close) {
withBlockStack.pop();
}
withBlockStack.push(block);
}
else if (blockAction === BlockAction.Close) {
withBlockStack.pop();
}
break;
// default: do nothing
}
}
}

View File

@ -2176,16 +2176,18 @@ namespace ts {
locked?: boolean;
}
export interface AfterFinallyFlow extends FlowNode, FlowLock {
export interface AfterFinallyFlow extends FlowNodeBase, FlowLock {
antecedent: FlowNode;
}
export interface PreFinallyFlow extends FlowNode {
export interface PreFinallyFlow extends FlowNodeBase {
antecedent: FlowNode;
lock: FlowLock;
}
export interface FlowNode {
export type FlowNode =
| AfterFinallyFlow | PreFinallyFlow | FlowStart | FlowLabel | FlowAssignment | FlowCondition | FlowSwitchClause | FlowArrayMutation;
export interface FlowNodeBase {
flags: FlowFlags;
id?: number; // Node id used by flow type cache in checker
}
@ -2193,30 +2195,30 @@ namespace ts {
// FlowStart represents the start of a control flow. For a function expression or arrow
// function, the container property references the function (which in turn has a flowNode
// property for the containing control flow).
export interface FlowStart extends FlowNode {
export interface FlowStart extends FlowNodeBase {
container?: FunctionExpression | ArrowFunction | MethodDeclaration;
}
// FlowLabel represents a junction with multiple possible preceding control flows.
export interface FlowLabel extends FlowNode {
export interface FlowLabel extends FlowNodeBase {
antecedents: FlowNode[];
}
// FlowAssignment represents a node that assigns a value to a narrowable reference,
// i.e. an identifier or a dotted name that starts with an identifier or 'this'.
export interface FlowAssignment extends FlowNode {
export interface FlowAssignment extends FlowNodeBase {
node: Expression | VariableDeclaration | BindingElement;
antecedent: FlowNode;
}
// FlowCondition represents a condition that is known to be true or false at the
// node's location in the control flow.
export interface FlowCondition extends FlowNode {
export interface FlowCondition extends FlowNodeBase {
expression: Expression;
antecedent: FlowNode;
}
export interface FlowSwitchClause extends FlowNode {
export interface FlowSwitchClause extends FlowNodeBase {
switchStatement: SwitchStatement;
clauseStart: number; // Start index of case/default clause range
clauseEnd: number; // End index of case/default clause range
@ -2225,7 +2227,7 @@ namespace ts {
// FlowArrayMutation represents a node potentially mutates an array, i.e. an
// operation of the form 'x.push(value)', 'x.unshift(value)' or 'x[n] = value'.
export interface FlowArrayMutation extends FlowNode {
export interface FlowArrayMutation extends FlowNodeBase {
node: CallExpression | BinaryExpression;
antecedent: FlowNode;
}

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();

View File

@ -441,10 +441,11 @@ namespace ts.server {
if (!this.eventHandler) {
return;
}
this.eventHandler(<ProjectLanguageServiceStateEvent>{
const event: ProjectLanguageServiceStateEvent = {
eventName: ProjectLanguageServiceStateEvent,
data: { project, languageServiceEnabled }
});
};
this.eventHandler(event);
}
updateTypingsForProject(response: SetTypings | InvalidateCachedTypings): void {
@ -602,10 +603,11 @@ namespace ts.server {
}
for (const openFile of this.openFiles) {
this.eventHandler(<ContextEvent>{
const event: ContextEvent = {
eventName: ContextEvent,
data: { project: openFile.getDefaultProject(), fileName: openFile.fileName }
});
};
this.eventHandler(event);
}
}
@ -1105,10 +1107,11 @@ namespace ts.server {
return;
}
this.eventHandler(<ConfigFileDiagEvent>{
const event: ConfigFileDiagEvent = {
eventName: ConfigFileDiagEvent,
data: { configFileName, diagnostics: diagnostics || emptyArray, triggerFile }
});
};
this.eventHandler(event);
}
private createAndAddConfiguredProject(configFileName: NormalizedPath, projectOptions: ProjectOptions, configFileErrors: ReadonlyArray<Diagnostic>, clientFileName?: string) {

View File

@ -540,7 +540,7 @@ namespace ts.server {
}
private convertToDiagnosticsWithLinePositionFromDiagnosticFile(diagnostics: ReadonlyArray<Diagnostic>): protocol.DiagnosticWithLinePosition[] {
return diagnostics.map(d => <protocol.DiagnosticWithLinePosition>{
return diagnostics.map<protocol.DiagnosticWithLinePosition>(d => ({
message: flattenDiagnosticMessageText(d.messageText, this.host.newLine),
start: d.start,
length: d.length,
@ -548,7 +548,7 @@ namespace ts.server {
code: d.code,
startLocation: d.file && convertToLocation(getLineAndCharacterOfPosition(d.file, d.start)),
endLocation: d.file && convertToLocation(getLineAndCharacterOfPosition(d.file, d.start + d.length))
});
}));
}
private getCompilerOptionsDiagnostics(args: protocol.CompilerOptionsDiagnosticsRequestArgs) {
@ -829,7 +829,7 @@ namespace ts.server {
return renameLocations.map(location => {
const locationScriptInfo = project.getScriptInfo(location.fileName);
return <protocol.FileSpan>{
return {
file: location.fileName,
start: locationScriptInfo.positionToLineOffset(location.textSpan.start),
end: locationScriptInfo.positionToLineOffset(textSpanEnd(location.textSpan)),

View File

@ -356,14 +356,15 @@ namespace ts.server.typingsInstaller {
this.sendResponse(this.createSetTypings(req, currentlyCachedTypings.concat(installedTypingFiles)));
}
finally {
this.sendResponse(<EndInstallTypes>{
const response: EndInstallTypes = {
kind: EventEndInstallTypes,
eventId: requestId,
projectName: req.projectName,
packagesToInstall: scopedTypings,
installSuccess: ok,
typingsInstallerVersion: ts.version // qualified explicitly to prevent occasional shadowing
});
};
this.sendResponse(response);
}
});
}