fix(compiler-cli): resolve type of exported *ngIf variable. (#33016)
Currently, method `getVarDeclarations()` does not try to resolve the type of exported variable from *ngIf directive. It always returns `any` type. By resolving the real type of exported variable, it is now possible to use this type information in language service and provide completions, go to definition and quick info functionality in expressions that use exported variable. Also language service will provide more accurate diagnostic errors during development. PR Close #33016
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user