TypeScript interview questions for freshers check whether you understand what types add to JavaScript. Expect questions on basic types, interfaces, unions, generics and the difference between TypeScript and JavaScript. This page has 25 questions with short answers. The code was compiled with TypeScript 5.9 in strict mode and run with Node.js to confirm the output and error messages.
How to answer TypeScript interview questions
Answer with the rule, a two-line example and the mistake it prevents. "unknown forces a type check before use. x.length on an unknown value does not compile, so you cannot call a method that may not exist."
Pro tip: Many TypeScript questions are really JavaScript questions. If you are unsure of closures, promises or
this, revise the JavaScript basics interview questions first.
TypeScript basics questions
Q1. What is TypeScript?
30-second answer: TypeScript is a language made by Microsoft that adds static types to JavaScript. You write .ts files, the TypeScript compiler checks the types, and it outputs plain JavaScript that runs in any browser or in Node.js. Every valid JavaScript program is also valid TypeScript syntax, though strict settings may report errors in it.
Q2. What is the difference between TypeScript and JavaScript?
| Point | JavaScript | TypeScript |
|---|---|---|
| Typing | Dynamic, checked while running | Static, checked before running |
| Runs directly | Yes, in browsers and Node.js | No, compiled to JavaScript first |
| Errors found | At run time | Many at compile time |
| Editor help | Basic | Strong autocomplete and refactoring |
| File extension | .js |
.ts, .tsx |
30-second answer: TypeScript is JavaScript plus a type system. The types catch mistakes such as passing a string where a number is expected, and then they are removed from the output.
Q3. Why do teams use TypeScript?
30-second answer: It catches type mistakes before the code runs, makes large codebases easier to change safely, and gives better autocomplete. The types also act as documentation: a function's signature tells you what it takes and returns.
Q4. How is TypeScript compiled?
30-second answer: The tsc compiler reads .ts files and tsconfig.json, reports type errors and writes .js files. Build tools such as Vite, Angular CLI and Next.js run this step for you.
npm install --save-dev typescript
npx tsc --init
npx tsc
tsc --init creates a tsconfig.json. Running npx tsc then compiles the project.
Q5. What is tsconfig.json?
30-second answer: It holds the compiler settings for a project: which files to include, the JavaScript version to output (target), the module system, the output folder and how strict the checks are. "strict": true turns on the strongest set of checks and is the normal choice for new projects.
Types questions
Q6. What are the basic types in TypeScript?
let age: number = 21;
let userName: string = "Asha";
let isFresher: boolean = true;
let skills: string[] = ["HTML", "CSS"];
let point: [number, number] = [10, 20];
console.log(age, userName, isFresher, skills, point);
Output:
21 Asha true [ 'HTML', 'CSS' ] [ 10, 20 ]
30-second answer: number, string, boolean, arrays, tuples, null, undefined, any, unknown, void, never, object, plus bigint and symbol. point is a tuple: a fixed-length array where each position has its own type.
Q7. What happens when you assign the wrong type?
let age: number = 21;
age = "twenty";
Compiler output:
error TS2322: Type 'string' is not assignable to type 'number'.
30-second answer: The compiler reports an error before the code runs. By default tsc still writes the JavaScript file, but build tools and CI usually fail on any error.
Q8. What is type inference?
30-second answer: TypeScript works out the type from the value when you do not write it. let count = 5; makes count a number, so count = "five" is an error. Write types on function parameters and public APIs, and let inference handle local variables.
Q9. What is the difference between any and unknown?
let x: unknown = "hello";
console.log(x.length); // error TS18046: 'x' is of type 'unknown'.
let y: any = "hello";
console.log(y.lenght); // compiles, prints undefined (typo not caught)
30-second answer: any turns type checking off, so even typos compile. unknown accepts any value but forces you to check its type before using it. Prefer unknown for data you do not trust, such as parsed JSON.
if (typeof x === "string") console.log(x.length); // prints 5
Q10. What are void and never?
30-second answer: void means a function returns nothing useful. never means a function never finishes normally, such as one that always throws or loops forever.
function log(msg: string): void { console.log(msg); }
function fail(msg: string): never { throw new Error(msg); }
Interface and type alias questions
Q11. What is an interface?
30-second answer: An interface describes the shape of an object: which properties it has and their types. ? marks an optional property and readonly blocks changes after creation.
interface User {
id: number;
name: string;
email?: string;
readonly createdAt: Date;
}
const u: User = { id: 1, name: "Ravi", createdAt: new Date(0) };
console.log(u.email ?? "no email"); // prints: no email
Writing u.createdAt = new Date(); gives error TS2540: Cannot assign to 'createdAt' because it is a read-only property.
Q12. What is the difference between interface and type?
| Point | interface |
type alias |
|---|---|---|
| Describes objects | Yes | Yes |
Unions such as "a" | "b" |
No | Yes |
| Extending | extends |
Intersection & |
| Declaration merging | Yes, two declarations combine | No, names must be unique |
30-second answer: Both can describe object shapes. Use type for unions, tuples and other combinations. Many teams use interface for object shapes and type for everything else. Either is fine if the team is consistent.
Q13. How does an interface extend another?
interface Person { name: string; }
interface Employee extends Person { empId: number; }
const e: Employee = { name: "Kiran", empId: 101 };
30-second answer: Employee has all of Person's properties plus its own. With type aliases, the same result is type Employee = Person & { empId: number }.
Union, narrowing and enum questions
Q14. What is a union type?
30-second answer: A union allows one of several types. A union of string values, called a literal union, limits a value to a fixed set.
type Status = "active" | "inactive";
function setStatus(s: Status) { return `status: ${s}`; }
console.log(setStatus("active")); // prints: status: active
setStatus("deleted") does not compile.
Q15. What is type narrowing?
30-second answer: Narrowing is when TypeScript works out a more exact type inside a check, such as typeof, instanceof, in or a comparison.
function format(value: string | number): string {
if (typeof value === "number") {
return value.toFixed(2);
}
return value.toUpperCase();
}
console.log(format(3.14159), format("ts"));
Output:
3.14 TS
Inside the if, value is a number; after it, TypeScript knows it is a string.
Q16. What are enums?
enum Role { Admin, Editor, Viewer }
console.log(Role.Editor, Role[0]);
enum Direction { Up = "UP", Down = "DOWN" }
console.log(Direction.Up);
Output:
1 Admin
UP
30-second answer: An enum is a named set of constants. Numeric enums start at 0 and also map numbers back to names, which is why Role[0] is Admin. String enums need a value for each member. Many teams use a literal union instead, because it adds no extra JavaScript.
Q17. What is a type assertion?
30-second answer: A type assertion tells the compiler "trust me, this is type X", written value as X. It does not change or check the value at run time, so a wrong assertion hides a bug. Use it only when you know more than the compiler, such as the exact type of a DOM element.
const input = document.getElementById("email") as HTMLInputElement;
Generics questions
Q18. What are generics?
30-second answer: Generics let one function or type work with many types while keeping type safety. T is a type parameter filled in when the function is called.
function first<T>(items: T[]): T | undefined {
return items[0];
}
const n = first([10, 20, 30]); // n is number | undefined
const s = first(["a", "b"]); // s is string | undefined
console.log(n, s); // prints: 10 a
Using any instead would lose the type of the result.
Q19. What is a generic constraint?
30-second answer: extends limits which types a generic accepts.
function longest<T extends { length: number }>(a: T, b: T): T {
return a.length >= b.length ? a : b;
}
console.log(longest("hello", "hi"), longest([1, 2], [1, 2, 3]));
Output:
hello [ 1, 2, 3 ]
Strings and arrays both have length, so both work. longest(10, 20) does not compile.
Q20. Can interfaces be generic?
30-second answer: Yes. A generic interface describes a shape with a type slot, such as an API response wrapper.
interface ApiResponse<T> {
data: T;
error?: string;
}
const res: ApiResponse<string[]> = { data: ["Asha", "Ravi"] };
Class and utility type questions
Q21. What do access modifiers do in TypeScript classes?
class Account {
private balance = 0;
constructor(public owner: string) {}
deposit(amount: number): void { this.balance += amount; }
getBalance(): number { return this.balance; }
}
const acc = new Account("Meena");
acc.deposit(500);
console.log(acc.owner, acc.getBalance()); // prints: Meena 500
30-second answer: public is the default and can be used anywhere. private can be used only inside the class, and protected also inside subclasses. public owner in the constructor declares and sets the property in one step. These checks happen at compile time only; JavaScript's own #balance syntax makes a field private at run time too.
Q22. What are Partial, Pick, Omit and Record?
| Utility type | Result |
|---|---|
Partial<User> |
All properties optional |
Required<User> |
All properties required |
Pick<User, "id" | "name"> |
Only those properties |
Omit<User, "email"> |
All except those |
Readonly<User> |
All properties read-only |
Record<string, number> |
Object with string keys and number values |
30-second answer: Utility types build new types from existing ones, so you do not repeat yourself. Partial is common for update forms, where only some fields change.
Q23. What are optional chaining and nullish coalescing?
30-second answer: a?.b returns undefined instead of throwing when a is null or undefined. a ?? b uses b only when a is null or undefined, unlike ||, which also replaces 0 and "". Both are JavaScript features that TypeScript supports and checks.
Q24. What does strictNullChecks do?
30-second answer: With it on (included in strict), null and undefined are not allowed in a type unless you add them, as in string | null. The compiler then makes you handle the missing case. This prevents the common "cannot read properties of undefined" error.
Q25. What is a declaration file (.d.ts)?
30-second answer: A .d.ts file contains only types, no code. It describes a JavaScript library so TypeScript can check how you use it. Many libraries include their own; others have types in @types/ packages, such as @types/node.
Quick revision table
| Topic | One line to remember |
|---|---|
| TypeScript | JavaScript plus static types, compiled to JS |
any vs unknown |
unknown forces a check first |
interface vs type |
type also does unions |
| Union | One of several types |
| Narrowing | typeof, instanceof, in inside checks |
| Generics | Reusable code with a type parameter |
strict |
Turns on the strongest checks |
| Utility types | Partial, Pick, Omit, Record |
How to prepare in one week
| Day | Task |
|---|---|
| 1 | Basic types, inference, any vs unknown |
| 2 | Interfaces, type aliases, optional and readonly |
| 3 | Unions, narrowing, enums |
| 4 | Generics and constraints |
| 5 | Classes and utility types |
| 6 | Convert a small JavaScript project with strict mode |
| 7 | Revise and do a mock interview |
If the role uses Angular, continue with Angular interview questions for freshers. For back-end roles, the Node.js interview questions page covers the runtime most TypeScript servers use.

