Typescript Typing like a pro(part2)still editing …
Jun 8, 2021
Keep on the previous track on Typescript types
Not commonly used types (never, unknown,void)
The never
type
TypeScript 2.0 introduces a new primitive type never
. The never
type represents the type of values that never occur. Specifically, never
is the return type for functions that never return and never
is the type of variables under type guards that are never true.
Examples of function returning never:
function error(message: string): never{
throw new Error(message);
}
function forCallback(cb:({cpu:number})=>void}):never{
cb({cpu:323});
}