Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I thought the same thing. I also have an assert function I pull in everywhere, and this trick seemed like it would be cleaner (especially for one-off scripts to reduce deps).

But unfortunately, using a default clause creates a branching condition that then treats the entire switch block as non-exhaustive, even though it is technically exhaustive over the switch target. It still requires something like throwing an exception, which at that point you might as well do 'const x: never = myFoo'.



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

Search: