Make it possible to create subclass of Node while keeping TS happy#2772
Conversation
c727d77 to
211041b
Compare
|
Nice, thanks! Indeed it would be nice to rename We could probably swap the two variables, and then mark |
That could work! Will probably play around with it a bit in my own app a bit to make sure it doesn't cause any issues first |
acd7047 to
8e27c03
Compare
8e27c03 to
2294ebd
Compare
Done!
@josdejong Tried it out in my app and seems good to go! |
|
Thanks Matt 👌 |
|
Published now in |
The Problem
Currently,
MathNodeis defined as a union of all of the existing subclasses ofNodei.e.This has a few consequences:
MathNodeunionNodewhen using mathjs while having that node conform to theMathNodetype so that TS is happyThe solution
By simply aliasing
MathNodetoMathNodeCommon(which all existing node types extend), typescript automatically infers that any subclasses ofNodeare validMathNodetypes.I did some digging and couldn't quite figure out why the
MathNodeCommontype needed to exist in the first place and why it couldn't just be calledMathNode, but it is what it is and I guess we can't change that now without a lot of breaking changes.