Typescript Typing like a pro(part2)still editing …

--

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});

}

--

--

hipster' Santos
hipster' Santos

Written by hipster' Santos

Fullstack developer , Distributed system engineer,Competitive programmer find at https://github.com/HipsterSantos

No responses yet