refactor(language-service): add type guard for NgLanguageService (#40954)

Type guard should be colocated with the `NgLanguageService` interface,
not in `@angular/vscode-ng-language-service`.

PR Close #40954
This commit is contained in:
Keen Yee Liau 2021-02-22 14:14:31 -08:00 committed by atscott
parent 3d8ac06e4b
commit 7101267923
3 changed files with 9 additions and 4 deletions

View File

@ -43,3 +43,8 @@ export interface NgLanguageService extends ts.LanguageService {
getTcb(fileName: string, position: number): GetTcbResponse|undefined;
getComponentLocationsForTemplate(fileName: string): GetComponentLocationsForTemplateResponse;
}
export function isNgLanguageService(ls: ts.LanguageService|
NgLanguageService): ls is NgLanguageService {
return 'getTcb' in ls;
}

View File

@ -247,8 +247,8 @@ export class LanguageService {
});
}
getTcb(fileName: string, position: number): GetTcbResponse {
return this.withCompiler<GetTcbResponse>(compiler => {
getTcb(fileName: string, position: number): GetTcbResponse|undefined {
return this.withCompiler<GetTcbResponse|undefined>(compiler => {
const templateInfo = getTemplateInfoAtPosition(fileName, position, compiler);
if (templateInfo === undefined) {
return undefined;
@ -496,4 +496,4 @@ function findTightestNodeAtPosition(program: ts.Program, fileName: string, posit
}
return findTightestNode(sourceFile, position);
}
}

View File

@ -130,7 +130,7 @@ export function create(info: ts.server.PluginCreateInfo): NgLanguageService {
return diagnostics;
}
function getTcb(fileName: string, position: number): GetTcbResponse {
function getTcb(fileName: string, position: number): GetTcbResponse|undefined {
return ngLS.getTcb(fileName, position);
}