What is type annotation in TypeScript?
Why Interviewers Ask This
This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex TypeScript topics. It also reveals how well you can explain technical ideas to non-experts.
Answer
Type annotation is the syntax for explicitly specifying the type of a variable, function parameter, or return value in TypeScript using a colon followed by the type. Examples: let name: string = "Alice";, let age: number = 30;, let isActive: boolean = true;. For functions: function greet(name: string): string { return "Hello, " + name; }. Arrays: let scores: number[] = [1, 2, 3]; or let scores: Array<number> = [1, 2, 3];. Objects: let user: { name: string; age: number } = { name: "Alice", age: 30 };. TypeScript can also infer types automatically — if you write let x = 5;, TypeScript infers x: number without an annotation. You should add explicit annotations when inference is not possible or when it improves code clarity.
Pro Tip
If you're unsure about a detail, say so honestly and explain your reasoning. Interviewers respect candidates who can think through uncertainty rather than bluffing.