TypeScript-Handbook icon indicating copy to clipboard operation
TypeScript-Handbook copied to clipboard

Full Handbook Page on Soundness

Open karlhorky opened this issue 6 years ago • 2 comments

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:

  1. What is soundness / type safety and why is it important?
  2. Maybe: what is completeness?
  3. An overview of the general state of soundness in TypeScript (maybe from Type Compatibility)
  4. 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:

karlhorky avatar Jul 04 '19 13:07 karlhorky

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.

orta avatar Aug 30 '19 13:08 orta

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.

karlhorky avatar Aug 30 '19 13:08 karlhorky