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
This commit is contained in:
Keen Yee Liau 2019-11-25 14:23:32 -08:00 committed by Matias Niemelä
parent d25de63ac8
commit 7cd16b9e2c
2 changed files with 13 additions and 1 deletions

View File

@ -271,7 +271,11 @@ class TypeWrapper implements Symbol {
} }
members(): SymbolTable { 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); } signatures(): Signature[] { return signaturesOf(this.tsType, this.context); }

View File

@ -128,6 +128,14 @@ describe('diagnostics', () => {
.toBe(`Identifier 'badProperty' is not defined. 'Hero' does not contain such a member`); .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, `
<test-comp (test)="myClick.bind(this)">
</test-comp>`);
const diags = ngLS.getDiagnostics(TEST_TEMPLATE);
expect(diags).toEqual([]);
});
describe('in expression-cases.ts', () => { describe('in expression-cases.ts', () => {
it('should report access to an unknown field', () => { it('should report access to an unknown field', () => {
const diags = ngLS.getDiagnostics(EXPRESSION_CASES).map(d => d.messageText); const diags = ngLS.getDiagnostics(EXPRESSION_CASES).map(d => d.messageText);