Add 'never' type - #8652
Merged
Merged
Conversation
Member
|
I really don't think this name is good for the general user experience. My feeling is that it seems to model several different things which the name doesn't reflect very well on. At least |
Member
Author
|
Daniel Rosenwasser (@DanielRosenwasser) The primary use for |
This PR introduces a
nevertype that represents the type of values that never occur. Specifically,neveris the return type for functions that never return andneveris the type of variables under type guards that are never true. Thenevertype has the following characteristics:neveris a subtype of and assignable to every type.never(exceptneveritself).returnstatements, or onlyreturnstatements with expressions of typenever, and if the end point of the function is not reachable (as determined by control flow analysis), the inferred return type for the function isnever.neverreturn type annotation, allreturnstatements (if any) must have expressions of typeneverand the end point of the function must not be reachable.Because
neveris a subtype of every type, it is always omitted from union types and it is ignored in function return type inference as long as there are other types being returned.The
nevertype replaces thenothingtype introduced in #8340 and it is effectively the same as thebottomtype proposed in #3076.Some examples of functions returning
never:Some examples of use of functions returning
never:Because
neveris assignable to every type, a function returningnevercan be used when a callback returning a more specific type is required:Fixes #3076.
Fixes #8602.