4 ms·
This linked project is very cool! I wonder if this path is expressly a non-goal of the TypeScript team though…?
by dfee 4y ago
This linked project is very cool! I wonder if this path is expressly a non-goal of the TypeScript team though…?
- brundolf 4y agoYeah, giving types a runtime footprint is on the official list of non-goals for the TypeScript project: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals#non-goals https://github.com/Microsoft/TypeScript/wiki/TypeScript-Desi...
- noduerme 4y agoInteresting. > Instead, encourage programming patterns that do not require run-time metadata. I can understand why. But there are times when any alternative pattern is a worse choice. Then it's left to the coder to hack together type checks however it's convenient. Does the Dog class really need a static variable typed to Dog|Cat... ? It would be nice if instead of a dozen nonstandard ways to do that, some metadata could be emitted if you wanted to. TS does weird stuff like emitting functions to define enums, for instance.
- brundolf 4y ago> Does the Dog class really need a static variable typed to Dog|Cat... ? It doesn't- because classes are a native JS concept and not a TS concept; they already have the metadata to distinguish them > TS does weird stuff like emitting functions to define enums, for instance Not sure what's meant by this; TypeScript does introduce enum syntax which technically generates runtime code (one of the few instances), though it's just very light sugar over constants, and using it is also sorta advised against these days
- noduerme 4y ago> classes are a native JS concept Recently, with ES6. But JS still lacks a way to get the type of an instance. You can check it but you can't simply get it, as in `new typeof(this)`. So you have to store it somewhere in the instance or in the type, as you would for a manual typeguard. And much of TS usage is still not for generating ES6 code. TS overlays boilerplate to mimick classes on ES5 targets. As it mimicks enums. I'm just saying I don't see why it couldn't mimick type reflection as well.