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

Why not support TypeScript natively in browsers instead?


https://github.com/giltayar/proposal-types-as-comments/#why-...

> Why not define a type system for JS in TC39 instead?

> TC39 has a tradition of programming language design which favors local, sound checks. By contrast, TypeScript's model -- which has been highly successful for JS developers -- is around non-local, best-effort checks. TypeScript-style systems are expensive to check at application startup, and would be redundant every time you run your JavaScript applications.

> Additionally, defining a type system to run directly in the browser means that improved type analyses would become breaking changes for the users of JavaScript applications, rather than for developers. This would [violate goals around web compatibility (i.e. "don't break the web")][1], so type system innovation would become near-impossible. Allowing other type systems to analyze code separately provides developers with choice, innovation, and freedom for developers to opt-out of checking at any time.

> In contrast, trying to add a full type system to JavaScript would be an enormous multi-year effort that would likely never reach consensus. This proposal recognizes that fact, and also recognizes that the community has evolved type systems that it is already happy with.

[1] https://github.com/tc39/how-we-work/blob/cc47a79340a773876cb...


This is essentially doing that—it would allow browsers to parse and run TypeScript. What it isn't doing is actually having browsers do type checking, for good reason: the TypeScript type checker is a large and complex piece of software, so browsers would either have to incorporate it (and they're probably not excited to have a large chunk of JS code in the critical web-page-rendering path, nor would they be excited to have a critical chunk of the browser with a single implementation), or reimplement it themselves (which would be a huge amount of work, and make changes to the language much slower and more difficult).


Ya this seems like an awesome idea. Let devs run the type checking before they ship code, and then let the browsers run the code just as they would plain JavaScript, ignoring the types. If someone's going to use TypeScript they would be tye checking it first anyway, so no real need to check it again at the browser.


The FAQ addresses this:

https://github.com/giltayar/proposal-types-as-comments#shoul...

https://github.com/giltayar/proposal-types-as-comments#shoul...

The idea is to avoid hampering competition, evolution, and innovation in the type-checking space.




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

Search: