Type annotation can be done by specifying type after a :
(colon).
Examples:
let num: number = 20;
function addNumbers(a: number, b:number ): number {
return a + b;
}
const addNumbers: number = (a: Number, b: Number) => {
return a + b;
}
Type-Inference
In typescript, not always have to define a type. It is smart enough to infer the correct type from the provided information.
Example:
const num = 20; // num is inferred as number as the value provided is number type.
const store = ["Adesh", 20]; // the type here is inferred as ('string'|'number')[]