Hacker News new | past | comments | ask | show | jobs | submit login

“exhaustiveness checking”: automatically making sure that we’ve covered all of the possible cases anywhere that we interact with a piece of data [1]

Typescript doesn’t do that.

There’s a way to manually force exhaustive checking with discriminating unions: https://github.com/basarat/typescript-book/blob/master/docs/...

However, it’s a manual workaround.

[1] Quoted from http://www.adamsolove.com/js/flow/type/2016/04/15/flow-exhau...




Hm? Typescript actually uses the same mechanism for exhaustiveness checking as flow (like your link describes).


It does. And, like in the article, Typescript is “saved by a hack”.

Compare that to Elm, where it will automatically fail compilation if you don’t include all required types in a switch statement. Without any hacks or manual intervention.


Oh, I know. Elm is far more elegant in that regard.

But just because I have to "switch on" exhaustiveness checks doesn't mean they don't exist.


Thing is, it only works in if and switch statements, you have to be aware of it (I don’t think you can deduce it from docs), and you have to manually trigger it.

It’s ”poor man’s exhaustiveness” and TS will hopefully get better at this




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

Search: