TypeScript-Handbook
TypeScript-Handbook copied to clipboard
Full Handbook Page on Soundness
From my tweet, where I suggested that it would be beneficial to have a Handbook page on Soundness:
https://twitter.com/karlhorky/status/1146687994142842880
My initial top-of-my-head suggestions in the tweet were to include at least the following information:
- What is soundness / type safety and why is it important?
- Maybe: what is completeness?
- An overview of the general state of soundness in TypeScript (maybe from Type Compatibility)
- What common structures or patterns can be expected to be unsound
Happy to add to the list, if anyone thinks of anything!
Unsound Behaviors
For 2. above, starting a list of unsound behaviors here:
No excess property checks in object types with spread (Playground)
- https://github.com/microsoft/TypeScript/pull/26798
- https://github.com/Microsoft/TypeScript/issues/17422
- potential solution: Exact Types
Incorrect definition of spread and Object.assign (Playground)
- https://github.com/microsoft/TypeScript/pull/28553
- https://github.com/microsoft/TypeScript/pull/28234
- https://github.com/microsoft/TypeScript/issues/31982
Trade-offs in Control Flow Analysis
- https://github.com/microsoft/TypeScript/issues/9998
This has been prompted by the high-quality criticisms as of late on Twitter by @sebmck:
- https://twitter.com/sebmck/status/1146524039227174914
- https://twitter.com/sebmck/status/1142601004241657856
This has been going on since ~ June 18:
- https://twitter.com/sebmck/status/1141052364331184128
Articles / discussion on the topic:
- Surviving the TypeScript Ecosystem — Part 3: Interfaces and Structural Typing
- Are unsound type systems wrong?
- Type-checking unsoundness: standardize treatment of such issues among TypeScript team/community?
- TypeScript Design Goals - Non-Goals: "Non-goal 3: Apply a sound or "provably correct" type system. Instead, strike a balance between correctness and productivity."
I've included an example on soundness in https://github.com/microsoft/TypeScript-Website/pull/43 which I think is probably enough, it doesn't aim to be comprehensive but it explains what soundness is, why TS isn't sound, provides examples and then links to the two main places where it is documented.
Ah cool, thanks @orta!
I think I would still suggest documenting and publicizing this more openly than an example - feels like having this in the top-level handbook documentation would help clear up a lot of things for beginners and experienced developers alike.