MCPcopy Create free account
hub / github.com/angular/angular / widenBinding

Function widenBinding

packages/compiler/src/typecheck/ops/bindings.ts:162–182  ·  view source on GitHub ↗
(expr: TcbExpr, tcb: Context, originalValue: string | AST)

Source from the content-addressed store, hash-verified

160 * Potentially widens the type of `expr` according to the type-checking configuration.
161 */
162export function widenBinding(expr: TcbExpr, tcb: Context, originalValue: string | AST): TcbExpr {
163 if (!tcb.env.config.checkTypeOfInputBindings) {
164 // If checking the type of bindings is disabled, cast the resulting expression to 'any'
165 // before the assignment.
166 return new TcbExpr(`((${expr.print()}) as any)`);
167 } else if (!tcb.env.config.strictNullInputBindings) {
168 if (originalValue instanceof LiteralMap || originalValue instanceof LiteralArray) {
169 // Object literals and array literals should not be wrapped in non-null assertions as that
170 // would cause literals to be prematurely widened, resulting in type errors when assigning
171 // into a literal type.
172 return expr;
173 } else {
174 // If strict null checks are disabled, erase `null` and `undefined` from the type by
175 // wrapping the expression in a non-null assertion.
176 return new TcbExpr(`(${expr.print()})!`);
177 }
178 } else {
179 // No widening is requested, use the expression as is.
180 return expr;
181 }
182}

Callers 3

executeMethod · 0.90
executeMethod · 0.90
tcbCallTypeCtorFunction · 0.90

Calls 1

printMethod · 0.45

Tested by

no test coverage detected