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
// Without a bottom type we would error :
// - Not all code paths return a value
// - Unreachable code detected
function foo(x: string | number) {
if (typeof x === "string") {
return true;
} else if (typeof x === "number") {
return false;
}
fail("Unexhaustive!");
}
function fail(message: string) { throw message; }
Confusion with void
void is a Unit. never is a falsum.
A function that returns nothing returns a Unit void. However a function that never returns (or always throws) returns never. void is something that can be assigned (wihout strictNullChecking) but never can never be assigned to anything other than never.
The text was updated successfully, but these errors were encountered:
i think the use case is not valid anymore. As I found that TypeScript doesn't infer throw or infinite loop to be bottom type never as the "return" value unless you explicitly declare it.
PR : microsoft/TypeScript#8652
Issue : microsoft/TypeScript#3076
Concept : https://en.wikipedia.org/wiki/Bottom_type
Add
bottom.md
in tips.Use case
Confusion with
void
void
is a Unit.never
is a falsum.A function that returns nothing returns a Unit
void
. However a function that never returns (or always throws) returnsnever
.void
is something that can be assigned (wihout strictNullChecking) butnever
cannever
be assigned to anything other thannever
.The text was updated successfully, but these errors were encountered: