From 7cd16b9e2c06e9c04f65911b0c5153d730b0f549 Mon Sep 17 00:00:00 2001 From: Keen Yee Liau Date: Mon, 25 Nov 2019 14:23:32 -0800 Subject: [PATCH] fix(language-service): function.bind() should not be an error (#34041) When performing diagnostic checks or completions, we should take into account members and properties in the base class, if any. Otherwise, the language service will produce a false error. PR closes https://github.com/angular/vscode-ng-language-service/issues/93 PR Close #34041 --- packages/language-service/src/typescript_symbols.ts | 6 +++++- packages/language-service/test/diagnostics_spec.ts | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/language-service/src/typescript_symbols.ts b/packages/language-service/src/typescript_symbols.ts index 73c7dfe28e..5dc538ed8b 100644 --- a/packages/language-service/src/typescript_symbols.ts +++ b/packages/language-service/src/typescript_symbols.ts @@ -271,7 +271,11 @@ class TypeWrapper implements Symbol { } members(): SymbolTable { - return new SymbolTableWrapper(this.tsType.getProperties(), this.context); + // Should call getApparentProperties() instead of getProperties() because + // the former includes properties on the base class whereas the latter does + // not. This provides properties like .bind(), .call(), .apply(), etc for + // functions. + return new SymbolTableWrapper(this.tsType.getApparentProperties(), this.context); } signatures(): Signature[] { return signaturesOf(this.tsType, this.context); } diff --git a/packages/language-service/test/diagnostics_spec.ts b/packages/language-service/test/diagnostics_spec.ts index ad0127d3ce..9504d9e627 100644 --- a/packages/language-service/test/diagnostics_spec.ts +++ b/packages/language-service/test/diagnostics_spec.ts @@ -128,6 +128,14 @@ describe('diagnostics', () => { .toBe(`Identifier 'badProperty' is not defined. 'Hero' does not contain such a member`); }); + it('should not produce errors on function.bind()', () => { + mockHost.override(TEST_TEMPLATE, ` + + `); + const diags = ngLS.getDiagnostics(TEST_TEMPLATE); + expect(diags).toEqual([]); + }); + describe('in expression-cases.ts', () => { it('should report access to an unknown field', () => { const diags = ngLS.getDiagnostics(EXPRESSION_CASES).map(d => d.messageText);