fix(language-service): infer $implicit value for ngIf template contexts (#35941)

Today, the language service infers the type of variables bound to the
"ngIf" template context member of an NgIf directive, but does not do the
same for the the "$implicit" context member. This commit adds support
for that.

Fixes https://github.com/angular/vscode-ng-language-service/issues/676

PR Close #35941
This commit is contained in:
ayazhafiz
2020-03-08 13:42:05 -07:00
committed by Matias Niemelä
parent 06779cfe24
commit 18b1bd4415
2 changed files with 49 additions and 3 deletions

View File

@ -144,6 +144,44 @@ describe('diagnostics', () => {
});
});
describe('diagnostics for ngIf exported values', () => {
it('should infer the type of an implicit value in an NgIf context', () => {
mockHost.override(TEST_TEMPLATE, `
<div *ngIf="title; let titleProxy;">
'titleProxy' is a string
{{~{start-err}titleProxy.notAProperty~{end-err}}}
</div>
`);
const diags = ngLS.getSemanticDiagnostics(TEST_TEMPLATE);
expect(diags.length).toBe(1);
const {messageText, start, length} = diags[0];
expect(messageText)
.toBe(
`Identifier 'notAProperty' is not defined. 'string' does not contain such a member`);
const span = mockHost.getLocationMarkerFor(TEST_TEMPLATE, 'err');
expect(start).toBe(span.start);
expect(length).toBe(span.length);
});
it('should infer the type of an ngIf value in an NgIf context', () => {
mockHost.override(TEST_TEMPLATE, `
<div *ngIf="title as titleProxy">
'titleProxy' is a string
{{~{start-err}titleProxy.notAProperty~{end-err}}}
</div>
`);
const diags = ngLS.getSemanticDiagnostics(TEST_TEMPLATE);
expect(diags.length).toBe(1);
const {messageText, start, length} = diags[0];
expect(messageText)
.toBe(
`Identifier 'notAProperty' is not defined. 'string' does not contain such a member`);
const span = mockHost.getLocationMarkerFor(TEST_TEMPLATE, 'err');
expect(start).toBe(span.start);
expect(length).toBe(span.length);
});
});
describe('diagnostics for invalid indexed type property access', () => {
it('should work with numeric index signatures (arrays)', () => {
mockHost.override(TEST_TEMPLATE, `