News for hackers. Stuff that matters.
Re:Love for TypeScript by peterkelly on Saturday July 30, 2016 @05:19AM (#12192274)
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.

There are no comments on this comment yet.