2 ms·
One thing I wonder is whether a “strict mode” subset of TS could be compiled to efficient code. Disallow “any” and most of the dynamic and meta programming feat
by iainmerrick 4y ago
One thing I wonder is whether a “strict mode” subset of TS could be compiled to efficient code. Disallow “any” and most of the dynamic and meta programming features of JS so it’s fully typesafe.
The type system is really nice, so even without being able to use the full range of JS hacks and escape hatches, I think it’d still be a nice language to work in.
- awestroke 4y agoTS by itself is not fully sound which could complicate such a compiler. Example: https://www.typescriptlang.org/play?#code/MYewdgzgLgBAtgTwLIEMAOAxArmYUCW4MAvDABT5QCmcAXDGFnAEZUBOANDCAG7sBmAGxAB3APz1obfGADmAShIA+GAG8AUDBj5+5SjRgqATDABkp7nzZDRMAISlGgwYo1atbKlCxswlgcIiANyaMAC+oZ7evtrUcAB0UCAAylDScmTyIWEhoJCwUAhoVMAo0KiYOHiEYPQUcfSMLOyKxCpSMrIk8Mjo2LgE4Lng0DCeEFiCsKQA2gCMHEYcAMwAuvFw6GSFxaXlfVWDYFkwAPSnMDtUEMDSaLAQKAgQlwAW+C8fMACCbGxPAB4OnIlFxmFhYJQYCJ8M4YKwYCh4PgAB7cXTA2QvFBgAAmDCYrDYEHUQA https://www.typescriptlang.org/play?#code/MYewdgzgLgBAtgTwLI... In the example above, the problem is that typescript allows casting function types to omit optional arguments, and also allows using a function with n arguments as a value where a function with >n arguments is expected
- iainmerrick 4y agoYes, those sorts of loopholes would need to be closed. I was imagining a subset of the language, but there might need to be some breaking changes to cover cases like that. Maybe it would end up being so different that it would be an entirely different language? I don't know! But it's hard for me to accept that non-soundness in TS is necessary for TS itself rather than just an unfortunate consequence of the JS language and library that it has to build on top of.