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

I actually discovered this in the TypeScript 1.x days (2013 I think) but I didn't even consider it pattern matching. I was probably calling it a type safe switch statement.

As the article points out, the value in doing this is if you have a lot of calling code that creates a switch statement, say on a "type". This solution will give compiler errors at all the callers if you add a new type, but a switch statement will not and just hit the default.




Applications are open for YC Summer 2020

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

Search: