mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-04 08:04:37 +08:00
A constructor's new.target dispatch skipped generic class families, so a generic subclass instantiated only in a body lowered later answered with the base's name, and `new.target === Base` held for its instances. A family now has its own arm, tested by its instanceof interval, which holds every instantiation: `new.target.name` reads the family's name and comparisons with a program class are false. Under an instantiation, the generic subclasses of its family are candidates too. `new.target` as a value refuses generic subclasses, which have no common class value. `new.target.name` reads a class's own static `name` field, which replaces its name (a subclass has its own name); a static method `name` or a non-string field is refused.
6 lines
284 B
TypeScript
6 lines
284 B
TypeScript
// new.target as a class value where a subclass is generic: its
|
|
// instantiations have no common class value.
|
|
class A { readonly t: typeof A; constructor() { this.t = new.target; } }
|
|
class B<T> extends A { readonly v: T | undefined = undefined; }
|
|
console.log(new B<number>().t.name);
|