feat(compiler): allow ngIf to use the ngIf expression directly as a guard
Allows a directive to use the expression passed directly to a property as a guard instead of filtering the type through a type expression. This more accurately matches the intent of the ngIf usage of its template enabling better type inference. Moved NgIf to using this type of guard instead of a function guard. Closes: #20967
This commit is contained in:

committed by
Alex Rickabaugh

parent
e48f477477
commit
82bcd83566
@ -123,7 +123,7 @@ export function convertPropertyBinding(
|
||||
return new ConvertPropertyBindingResult([], outputExpr);
|
||||
}
|
||||
|
||||
stmts.push(currValExpr.set(outputExpr).toDeclStmt(null, [o.StmtModifier.Final]));
|
||||
stmts.push(currValExpr.set(outputExpr).toDeclStmt(o.DYNAMIC_TYPE, [o.StmtModifier.Final]));
|
||||
return new ConvertPropertyBindingResult(stmts, currValExpr);
|
||||
}
|
||||
|
||||
@ -334,7 +334,13 @@ class _AstToIrVisitor implements cdAst.AstVisitor {
|
||||
}
|
||||
|
||||
visitLiteralPrimitive(ast: cdAst.LiteralPrimitive, mode: _Mode): any {
|
||||
return convertToStatementIfNeeded(mode, o.literal(ast.value));
|
||||
// For literal values of null, undefined, true, or false allow type inteference
|
||||
// to infer the type.
|
||||
const type =
|
||||
ast.value === null || ast.value === undefined || ast.value === true || ast.value === true ?
|
||||
o.INFERRED_TYPE :
|
||||
undefined;
|
||||
return convertToStatementIfNeeded(mode, o.literal(ast.value, type));
|
||||
}
|
||||
|
||||
private _getLocal(name: string): o.Expression|null { return this._localResolver.getLocal(name); }
|
||||
|
Reference in New Issue
Block a user