Files
scriptc/tests/diagnostics/class-call-shadowed-static.ts
T
Chris Tate 5966f23bd3 Keep the class-value call fence when a subclass declares a static call
`C.call(...)` through a class value typed as `Base` may run a subclass's own
static `call`, which Node calls instead of the class constructor. The
constructor-call lowering now applies only when no class the receiver can
hold declares a static `call` or `apply`: the class and its bases (any
static member of that name, including accessors, fields without
initializers and computed names), and, for a receiver that may hold a
subclass, every subclass. Otherwise the call keeps its existing
diagnostic.
2026-10-22 20:33:33 -05:00

16 lines
456 B
TypeScript

// Through a class value that may hold a subclass, `C.call(...)` reaches the
// subclass's own static `call` when it declares one, so the call is not the
// constructor call that throws Node's TypeError.
class Base {
n = 1;
}
class OwnCall extends Base {
static call(value: unknown): string {
return `own call ${typeof value}`;
}
}
function callThrough(C: typeof Base): unknown {
return C.call(new Base());
}
console.log(callThrough(OwnCall));