3 ms·
> So it doesn't achieve its stated goal of letting you run Typescript in the browser. At risk of running afoul of HN guidelines: did you actually read the post
by ketzo 5y ago
> So it doesn't achieve its stated goal of letting you run Typescript in the browser.
At risk of running afoul of HN guidelines: did you actually read the post?
The proposal does not add type checking to JavaScript. It adds type syntax. There is a huge, huge difference.
Their proposal is to implement a comment-like type syntax. These types would be totally ignored at runtime.
This isn't "run TypeScript in the browser"; this is "add syntactic sugar to vanilla JavaScript to get the development benefits of types without a build step."
Yes, JavaScript engines would have to implement a parser for this syntax. Yes, this raises the barrier to building a new JavaScript engine.
Does that mean JavaScript should add no new syntax ever again? No, of course not. So the question becomes one of cost-benefit analysis. And I think the TS team has submitted an extremely compelling argument for the benefits.
Your comment acknowledges the existing benefits of types-in-comments; think of this proposal as a significantly nicer way to write those.
- 14u2c 5y agoIn fact, this would be quite nice for TypeScript compile TO. JS engines could use the automatically generated type hints optimization, validation, reflection, etc.
- krapp 5y ago>Does that mean JavaScript should add no new syntax ever again? No, of course not. Yes? Yes. Maybe? At least not in cases where the language can already do things adequately, and the change is just a cosmetic improvement. Annotating comments already works, changing that just to have a syntax that looks like type hinting but isn't just makes the language worse in my opinion. I'd rather they just bite the bullet and add optional type hinting, and make the syntax do what it appears to. Otherwise, the necessary complexity of typing Javascript should be kept entirely out of the language itself - including special syntax to make things easier. Deal with Typescript and its peculiarities and the build step, if that's what you want to do, and annotate types in the existing comment syntax, but Javascript is an untyped language and should be remain absolutely, even aggressively agnostic about such things.
- exclipy 5y agoYes I completely understand that it's not about adding type checking in the browser. My complaint is about adding type parsing in the browser. When I say "run typescript on the browser", I mean running code written in typescript syntax. Please read my comment again with that in mind.