4 ms·
They wrote: "The TypeScript compiler could theoretically perform bundle optimizations based on types and you are missing on that by having a separate emitter an
by evmar 8y ago
They wrote: "The TypeScript compiler could theoretically perform bundle optimizations based on types and you are missing on that by having a separate emitter and type checker."
Actually, this isn't true, and it's a fundamental property of TypeScript. It's actually the secret to being a TypeScript wizard, and the more you internalize it, the more questions about TypeScript you can answer in advance. I go through some others here: http://neugierig.org/software/blog/2016/04/typescript-types.html http://neugierig.org/software/blog/2016/04/typescript-types....
It's an important property in part for exactly the reasons this author worries about it -- it preserves the property always safe to type check and emit separately.
It's so fundamental to TS that their bug tracker, when reporting a bug, has a checkbox about whether your request violates this property, and if so they will discard your bug.
- munchor 8y agoAuthor here, I actually addressed this in a footnote linked directly to that sentence you quoted. EDIT: This is incorrect ^, I misread your comment at first. Thank you for bringing this up, this makes me feel even better about using Babel to emit code.
- RussianCow 8y agoI might be missing something, but that sentence does not appear to have a footnote, nor do any of the footnotes directly address the OP's comment.
- munchor 8y agoOops, you're right, I misunderstood the original comment.
- evmar 8y agoIt was a great post, sorry to only have written a criticism! I vaguely recall there was some issue with the Babel emit of enums, but I can't remember it well enough to even remember whether it was fixed or not.
- atombender 8y agoIt's really the most important feature/aspect of TypeScript -- the fact that it's just a type-checking veneer on top of JavaScript. It's not its own language like Dart or the myriad of languages (Reason, PureScript, etc.) that transpiled to JavaScript. It's not just that its types are erased at runtime, as you point out; there are many nuances caused by the fact that it's a superset of JS. While I think TypeScript is the best we have right now, I'm also a bit sad that we need to endure this kind of compromise. Maybe once Wasm because widely supported we can finally cast away the JS legacy and begin anew.