You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
function weird() {
function generateStringOrNumber(): string | number {
if (Math.random() > 0.5) {
return 42;
} else {
return "blabla";
}
}
return; // this causes problems
const value = generateStringOrNumber();
if (typeof value !== "string") {
const numberValue: number = value;
}
}
Actual behaviour
Compiler error
Type 'string | number' is not assignable to type 'number'.
Type 'string' is not assignable to type 'number'.(2322)
Expected behaviour
Should compile fine
Notes
Remove return in function, and it actually compiles fine.
The text was updated successfully, but these errors were encountered:
Playground link
playground
Code
Actual behaviour
Compiler error
Expected behaviour
Should compile fine
Notes
Remove return in function, and it actually compiles fine.
The text was updated successfully, but these errors were encountered: