diff --git a/packages/compiler-cli/src/diagnostics/expression_diagnostics.ts b/packages/compiler-cli/src/diagnostics/expression_diagnostics.ts index b00ef4659d..2253d2c077 100644 --- a/packages/compiler-cli/src/diagnostics/expression_diagnostics.ts +++ b/packages/compiler-cli/src/diagnostics/expression_diagnostics.ts @@ -154,6 +154,19 @@ function refinedVariableType( } } + // Special case the ngIf directive ( *ngIf="data$ | async as variable" ) + const ngIfDirective = + templateElement.directives.find(d => identifierName(d.directive.type) === 'NgIf'); + if (ngIfDirective) { + const ngIfBinding = ngIfDirective.inputs.find(i => i.directiveName === 'ngIf'); + if (ngIfBinding) { + const bindingType = new AstType(info.members, info.query, {}).getType(ngIfBinding.value); + if (bindingType) { + return bindingType; + } + } + } + // We can't do better, return any return info.query.getBuiltinType(BuiltinType.Any); } diff --git a/packages/compiler-cli/test/diagnostics/expression_diagnostics_spec.ts b/packages/compiler-cli/test/diagnostics/expression_diagnostics_spec.ts index 2b7c581407..9dcb990e92 100644 --- a/packages/compiler-cli/test/diagnostics/expression_diagnostics_spec.ts +++ b/packages/compiler-cli/test/diagnostics/expression_diagnostics_spec.ts @@ -130,6 +130,18 @@ describe('expression diagnostics', () => { `, 'Identifier \'nume\' is not defined')); + it('should accept an async *ngIf', () => accept(` +