mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-01 07:33:12 +08:00
`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.
16 lines
456 B
TypeScript
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));
|