Files
scriptc/tests/fixtures/npm-static/class-options-cli.ts
T
Chris Tate f291f1c275 Monomorphize destructured options parameters of package functions
A package function that destructures its options object, such as
makeClass({ Base, name }), now specializes per call site like positional
parameters: each destructured name binds the static type of the matching
property, so a class passed as { Base } keeps its static type and
class extends Base builds a constructible subclass.

Fixes #938
Co-authored-by: phall <25888173+phall1@users.noreply.github.com>
2026-10-17 20:50:59 -05:00

16 lines
661 B
TypeScript

// A package factory that receives its base class through a destructured
// options object builds subclasses of program classes that construct and
// dispatch like Node.
import { Class, extend } from "class-options/classes.js";
class Animal extends Class("Animal") {}
class Dog extends extend(Animal, "Dog") {}
class Puppy extends extend(Dog, "Puppy") {}
const rex = new Dog("Rex");
const ada = new Animal("Ada");
const bit = new Puppy("Bit");
console.log(rex instanceof Dog, rex instanceof Animal, ada instanceof Dog, bit instanceof Animal);
console.log(rex.describe(), ada.describe(), bit.describe());
console.log(rex.kind, rex.value, ada.kind, bit.label);