r/programming • • Aug 20 '20

Announcing TypeScript 4.0

https://devblogs.microsoft.com/typescript/announcing-typescript-4-0/
1.3k Upvotes

236 comments sorted by

View all comments

Show parent comments

8

u/StillNoNumb Aug 21 '20 edited Aug 21 '20

The situation of TS is very different to what Rust does though. Rust has very well-defined sound typing; for every piece of correct code, there is parts of the documentation explaining why it is correct. TypeScript is very different, it's not sound at all and the compiler letting code pass through doesn't mean it's actually correct. Instead, TypeScript helps you by catching as many errors as possible - and with any new release, it might help you find more errors. However, many of these things aren't documented at all, so deciding what's a breaking change is much harder.

For example, take Record<number, string> and Record<0 | 1 | 2, string>. The latter expects a value with ALL three keys (and they're all required): 0, 1, and 2, while the keys in the former are optional (the empty object would work). Special casing like that complicates typing rules by a lot - but it just so turned out to help catch the most errors for the wide variety of code written that uses Record.

Creating a precise specification for such a system while still giving the opportunity to extend it is nearly impossible.

1

u/BroBroMate Aug 21 '20

And so changing that Record interface in a way that breaks code relying on is absolutely a major version bump. Even if you can't create a spec for it, you could at least regression test it to catch breaking changes.