Skip to content
Laviyx Learn

Try

TypeScript course menu

Beginner TypeScript Interview Questions and Answers

Common TypeScript interview questions for freshers with clear answers: what TypeScript is, its benefits, type annotations and inference, interface vs type, any vs unknown, union and literal types, optional properties, void and never, and enums.

Beginner4 min readUpdated
On this page

These questions are common for front-end, full-stack and Node.js roles that use TypeScript. Answer each one out loud first, then check. A clear explanation with a small example is what interviewers look for.

Show solution

TypeScript is a superset of JavaScript that adds static types. Any valid JavaScript is (mostly) valid TypeScript. The TypeScript compiler checks the types and then removes them, producing plain JavaScript that runs in browsers and Node.js. Types exist only at compile time.

2. What are the benefits of TypeScript?#

Show solution

Errors such as wrong argument types, misspelled properties and unhandled null are caught before the code runs; editors give accurate auto-complete, inline documentation and safe refactoring; types document how code should be used; and large codebases are easier to change safely. The costs are a build or type-check step and learning the type system.

3. What is type inference?#

Show solution

TypeScript works out types without annotations, from initial values (let count = 0 is a number), return statements and context (callback parameters in array.map((x) => ...)). You annotate where inference cannot help or where the type documents intent: function parameters, public return types and outside data.

4. What is the difference between interface and type?#

Show solution

Both can describe object shapes. interface can be extended with extends and supports declaration merging (two declarations with the same name combine). type can name any type, including unions, tuples, primitives and function types, and composes with &. A common convention is interfaces for object shapes and type aliases for everything else.

5. What is the difference between any and unknown?#

Show solution

Both accept any value. any turns off type checking, so you can use the value in any way, even incorrectly. unknown must be narrowed (with typeof, instanceof, a type guard and so on) before it can be used, which makes it the safe choice for outside data such as JSON or caught errors.

6. What are union types?#

Show solution

A union A | B means a value can be either type. Before narrowing, you can only use what all members share; after a check such as typeof value === "string", TypeScript knows the specific type. Unions with null or undefined model optional values: string | null.

7. What are literal types?#

Show solution

Types that allow one exact value, such as "left" or 42. In unions, they describe a fixed set of allowed values: type Size = "small" | "medium" | "large". They catch typos and enable auto-complete.

8. What do ? and readonly mean on a property?#

Show solution

prop?: T makes the property optional (its type includes undefined, so it must be checked before use). readonly prop: T prevents reassigning the property after creation; this is checked at compile time only.

9. What is the difference between void and never?#

Show solution

void is the return type of a function that returns no useful value (it finishes normally). never is the type of something that never happens: a function that always throws or loops forever, or a value in a branch that has been ruled out completely. never is used for exhaustiveness checks.

10. What is strict mode?#

Show solution

"strict": true in tsconfig.json enables a group of checks, most importantly strictNullChecks (null and undefined must be handled explicitly) and noImplicitAny (no silent any types). It should be enabled in every new project.

11. How do you type an array and a tuple?#

Show solution

Arrays: number[] or Array<number>. Tuples have a fixed length and a type per position: [string, number], for example ["maths", 92]. Use readonly number[] for arrays that must not be modified.

12. What are enums, and what are the alternatives?#

Show solution

Enums define named constants that exist at runtime: enum Status { Active = "ACTIVE", Inactive = "INACTIVE" }. Numeric enums auto-increment and reverse-map. Many teams prefer string literal unions ("active" | "inactive") or as const objects, which need no special compilation, accept plain strings and work with tools that only strip types.

13. How do you type a function?#

Show solution

Annotate parameters and, optionally, the return type: function add(a: number, b: number): number. Optional parameters use ?, defaults use =, rest parameters are arrays (...nums: number[]). A function type is written as (a: number, b: number) => number.

14. Do TypeScript types exist at runtime?#

Show solution

No. Types are erased during compilation, so you cannot check if (value is User) at runtime using a TypeScript type. Runtime checks need JavaScript (typeof, instanceof, property checks), usually wrapped in type guard functions or validation libraries such as Zod.

Keep going#

Move on to the intermediate TypeScript questions, or browse every question with hints on the TypeScript interview page.

Finished this lesson?