Class expressions: illegal assignments are allowed #39469
Labels
Bug
A bug in TypeScript
Effort: Moderate
Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".
Fix Available
A PR has been opened for this issue
Help Wanted
You can do this
Milestone
TypeScript Version: 4.0.0-dev.20200707
Search Terms: Subclassing, class expression, constructor, inheritance
Expected behavior:
My anonymous class expression should not be assignable to
SortedArray
because thebrand
is missing.Actual behavior:
The class expression is assignable to
SortedArray
. This compiles, but breaks in runtime.Related Issues:
Code
I wanted a nominal, array-like structure to represent sorted arrays. It should have the same API as
ReadonlyArray
. I'm subclassing the built-inArray
constructor under the hood.This breaks in runtime — we never defined
brand
on the anonymous class.Output
Compiler Options
Playground Link: Provided
The text was updated successfully, but these errors were encountered: