Typescript add Annotation onto Functions

Type annotations for functions – Code we add to tell Typescript what type of arguments a function will receive and what type of values it will return.

Type inference for functions – TS tries to figure out what type of value a function will return.

Alternate forms of syntax

Annotate a by providing type number
Annotate b by providing type number
Annotate the return value by providing type number

if no return value, we can specify void

TypeScript introduced a new type never, which indicates the values that will never occur.

Difference between never and void

ref – https://www.tutorialsteacher.com/typescript/typescript-never

The void type can have undefined or null as a value where as never cannot have any value.

A function that has return type void, and no return value, actually defaults to return undefined.

If you you use never type, then sayHi will give a compile time error, as void is not assignable to never.

Destructuring with Annotation

In order to do parameter destructuring, we do this:

Annotation with Objects