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

Sort of. I tried the above and it reported the following error message:

error TS2354: No best common type exists among return expressions.

So at least it detects the problem. However the type inference algorithm should arguably return a union type here.

I find it good practice to always specify the return type of functions anyway. Then it will pick up cases where you return a type you didn't intend to; instead of just using a more general type it will tell you about the inconsistency.



Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

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

Search: