Essential TypeScript Interview Questions — PART — 3
1 min readAug 2, 2024
In modern development, TypeScript has become a staple for ReactJS, NodeJS, and Angular applications. Here are some crucial TypeScript questions you might encounter in an interview.
Photo by Jon Tyson on Unsplash
11. What is a String enum
?
String enums hold string values:
enum allDirections {
North = "North",
East = "East",
South = "South",
West = "West"
};
let currentDirection = allDirections.North; // "North"
12. What are Type Aliases?
Type aliases define custom types:
type Year = number;
type Car = { year: Year, type: string, model: string };
const car: Car = { year: 2005, type: "Tata", model: "Tiago" };
13.What are interfaces?
Interfaces define object shapes:
interface Square {
length: number;
}
const square: Square = { length: 20 };
14.How to extend interfaces?
Use the extends
keyword:
interface Square {
length: number;
}
interface ColorSquare extends Square {
color: string;
}
const square: ColorSquare = { length: 20, color: 'blue' };
15.What are Union types?
Union types allow variables to hold multiple types:
function printSuccessCode(code: string | number) {
console.log(`My success code is ${code}.`);
}
printSuccessCode(200);
printSuccessCode('200');