Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Interesting.

> 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.



> 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


> 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: