MCPcopy Index your code
hub / github.com/angular/angular / widenBinding

Function widenBinding

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

Source from the content-addressed store, hash-verified

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

Callers 3

executeMethod · 0.90
executeMethod · 0.90
tcbCallTypeCtorFunction · 0.90

Calls 1

printMethod · 0.45

Tested by

no test coverage detected