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.
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.