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

Generics in typescript do not affect codegen, they are only visible to the typechecker.

The main typescript features that require specialist codegen for ESNext targets are enums (especially const enums) and namespaces. These were added in the past when typescript was less strict about adding features that affect codegen, if proposed today they would not be accepted as typescript now has a policy of waiting for JavaScript to implement features first.



What about this article, which says the type level programming features constitute a turing complete system: https://mjj.io/2021/03/29/type-level-programming-in-typescri...

Edit: ok, it says it affects whether the program will typecheck, so it's consistent with not affecting code generation.

(More Turing completeness discussion at https://github.com/Microsoft/TypeScript/issues/14833)

Then there are other features that have no equivalent in JS. For example enums. And the handbook talks about what kind of JS they "compile to".


See the last paragraph of zarzavat's comment :) They wouldn't be added today, and they aren't widely used any more (they have non-codegen alternatives now). In other words, breaking changes in semantics shouldn't be a worry any more, since the TS team has consciously decided to attempt to avoid them a few years ago.




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

Search: