Discussion on Type Annotations and Type Inference

Type Annotations: Type Annotations is used to define the types of variable, function parameters, return values and object properties.
Example:

// Variables 
let value:string="Hello My Name is John Doe";
let secondValue:number=12;
secondValue=12-1; // No issue 
secondValue="12" // This returns type issue as we have define type number to secondValue
let thirdValue:boolean=true
//Functions
function random(name:string):string{
return `Welcome ${name}`; 
}
//In above function we define function params as type string which returns type string
//Objects
const data:{name:string,id:number}={name:"John Doe",id:12}

Type Inference: Typescript Compiler automatically defines or infers the type of variable based on the value defined to it. This property of typescript is known as type inference.

let randomValue="John Doe"
//In this case TypeScript Compiler automatically assigns the type of randomValue to string.
randomValue="Janet"
randomValue=12 //shows type error: Error: Type 'number' is not assignable to type 'string'