mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-12 02:13:04 +08:00
`const kinds = [Dog, Cat, Animal]; new kinds[0]()` now works as in Node:
- TypeScript: the checker types the element as the common base
(`typeof Animal`), and an element read keeps the `undefined` an index
past the end reads. The construction now narrows the class value out of
that union, and an index past the end throws Node's TypeError
("kinds[5] is not a constructor"). Before, it refused with SC2001.
- JavaScript: such a literal is a checked-dynamic array stored in a slot
of the base's class values, and the check accepted only the base's own
class value, so storing it threw "expected class constructor".
A class value of a subclass now checks into its base class's slot, as a
subclass instance already checks into a base-class instance slot.
Classes without subclasses keep the exact check.