New to Rust? Grab our free Rust for Beginners eBook Get it free →
Top 50 TypeScript Interview Questions

Practicing TypeScript interview answers means explaining concepts clearly, not just naming them. TypeScript lets teams describe expected values in source code.
This article provides answers to common questions and a step-by-step example of narrowing uncertain values.
TL;DR: TypeScript interview questions
A strong answer defines the concept, gives a small example, and names the limit of what the type checker proves.
- Explain compile-time checking separately from JavaScript runtime behavior.
- Practice unions, narrowing, generics, and structural object types.
- Treat external data as unknown until runtime validation establishes its shape.
What is TypeScript?
TypeScript lets teams describe expected values in source code.
In an interview, separate what the checker can establish from behavior that depends on values at runtime.
How to answer TypeScript interview questions step by step
I ran the discriminated-union example below with TypeScript 7.0.2 and Node.js v26.7.0.
Step 1: Describe the value shapes
The shared kind field identifies which result shape is available in each branch.
type ApiResult = { kind: "ok"; value: string } | { kind: "error"; message: string };
function describe(result: ApiResult): string {
if (result.kind === "ok") return `Value: ${result.value}`;
return `Error: ${result.message}`;
}
console.log(describe({ kind: "ok", value: "ready" }));
console.log(describe({ kind: "error", message: "not found" }));
The output from node interview-demo.js was exactly: Value: ready
Error: not found

Step 2: Narrow uncertain values
The guard returns a label for a string value.
function label(value: unknown): string {
if (typeof value === "string") return value.toUpperCase();
return "unsupported value";
}
The string branch returns an uppercase label, while other inputs receive the fallback.
Step 3: Explain how the compiler checks a project
I use noEmit when another build tool owns JavaScript generation, so the project check does not produce a second set of files.
{
"compilerOptions": {
"strict": true,
"noEmit": true
},
"include": ["src"]
}
Run tsc -p . to check the configured project against its compiler options.
TypeScript interview questions with answers
These answers cover common definitions and follow-up distinctions. Explain the type relationship and its runtime boundary rather than reciting a label.
1. What is TypeScript, and how does it differ from JavaScript?
The compiler emits JavaScript for the chosen runtime.
2. Why use TypeScript?
Types describe expected values, helping tools flag mismatches and navigate code. They also coordinate changes across modules.
3. Is TypeScript statically typed?
Yes. The language includes static types.
4. What is type inference?
Inference means the checker derives a type from an initializer, return expression, or surrounding context. It reduces annotations when the resulting type communicates the contract clearly.
5. What are the basic types?
TypeScript includes primitive and composite types, along with literal types. For example, “open” is narrower than string, and 3 is narrower than number.
6. How do arrays and tuples differ?
A tuple gives positions their own types, as in [string, number], and can include optional or rest elements.
7. What is any?
Because any disables checking as a value moves through assignments and calls, it can hide assumptions. Keep it at a temporary migration boundary instead of letting it spread.
8. What is unknown?
unknown accepts any assigned value. A check or assertion is required before type-specific operations.
9. What is never?
never describes an impossible value or a function that does not return normally. In a switch, the remaining value has type never after every case is handled.
10. What is void?
A function typed void may return undefined at runtime, even though callers are expected to ignore its result.
11. How do null and undefined differ?
JavaScript uses undefined for absent or uninitialized values and null for an explicitly empty value. With strictNullChecks, include either in a union when a variable or property can hold it.
12. What does strict mode do?
The tsconfig strict option enables a family of stronger checks, including strict null checks and noImplicitAny. It improves static feedback across the project.
13. What is a union type?
A union such as string | number permits either member. Before a branch distinguishes them, use only operations valid for both.
14. What is an intersection type?
An intersection A & B requires a value to satisfy both types. It combines object requirements, though conflicting property definitions can make a result unusable or impossible to construct.
15. What is type narrowing?
Checks such as typeof, equality, in, instanceof, and discriminant fields refine a type within a branch.
16. What is a discriminated union?
A discriminated union uses a shared field with a distinct literal for each member, such as kind: “ok” or kind: “error”.
17. How do you check every union case?
Add an exhaustive check so a newly added union member exposes an incomplete switch.
18. What is a type guard?
A custom predicate returns a signature like value is User. Its implementation must test that shape accurately.
19. What is an interface?
An interface names an object shape and can be extended or implemented by classes. Interface declarations can merge when they share a name, which is useful for intentional augmentation but can surprise when accidental.
20. What is a type alias?
Unlike a nominal type, an alias does not create a distinct identity. It can name primitives, unions, tuples, and mapped types, but it does not declaration-merge.
21. Interface or type: which should you choose?
Choose an interface for an extendable object contract and a type alias for unions, tuples, or computed combinations. Both describe structural types, so follow the project’s established convention.
22. What is structural typing?
Compatibility is usually based on members a value has rather than a declared class name. Structural compatibility lets independently declared object types work together when their required members match.
23. What are optional properties?
A property marked with ? may be absent, so reading it can produce undefined. Test for presence or use a default.
24. What does readonly mean?
readonly prevents assignment through that typed property after initialization. This is a shallow compile-time restriction, so another reference can still mutate the object.
25. What is keyof?
keyof T produces a union of the known property keys of T. It is often paired with a generic K extends keyof T so a function can accept only keys valid for the object.
26. What does typeof mean in a type position?
In a type position, typeof derives a static type from a value name. In an expression, JavaScript typeof returns a runtime string.
27. What are indexed access types?
T[“name”] retrieves the type of a property from T. With a key union, T[keyof T] forms a union of property value types, useful for deriving types from an existing model.
28. What is a generic?
A generic introduces a type parameter that relates values across an API. An identity function can accept T and return T, preserving information that a version using any would discard.
29. What is a generic constraint?
A constraint such as T extends { length: number } requires an input with a length property and lets the function use that property. It describes a capability shared by accepted types.
30. What is a generic default?
A type parameter may declare a default used when callers omit it. Defaults make APIs shorter for common cases, while explicit type arguments remain available when inference needs help.
31. What is a conditional type?
A conditional type selects a type based on assignability, using the form T extends U ? X : Y. When the checked type parameter is naked, the condition can distribute over union members.
32. What does infer do?
infer declares a type variable inside the extends side of a conditional type and captures a matching part of a structure. For example, it can extract an element or return type.
33. What are mapped types?
A mapped type iterates over keys in a type and builds a new property set. Readonly
34. What does Pick do?
Pick
35. What does Omit do?
Omit
36. What does Partial do?
Partial
37. What does Record do?
Record<K, V> maps each key in K to a value of type V, and a finite key union can require an entry for every named case.
38. What is satisfies?
The satisfies operator checks that an expression fits a target type while retaining more specific inferred details. TypeScript 4.9 introduced the operator.
39. What is a type assertion?
An assertion such as value as User tells the checker how to treat a value. Use an assertion only when separate evidence supports the claim.
40. What are function overloads?
Overload signatures expose several accepted call shapes, followed by one implementation signature. The implementation must handle all cases, and callers see the overloads rather than the implementation signature.
41. What are optional and rest parameters?
Check an optional parameter for undefined before using it.
A rest parameter collects remaining arguments into an array with a declared element type.
42. What are enums?
An enum declares named constants and may emit a runtime object, depending on its form and compiler settings. Literal unions are an alternative when a runtime enum object is not needed.
43. What is a class?
TypeScript checks the declared members, then emitted JavaScript provides the runtime behavior. A class defines instance behavior and a constructor, and extends supplies inheritance.
44. What do public, private, and protected mean?
These TypeScript access modifiers restrict access during type checking. JavaScript #private fields have runtime-enforced privacy, so choose according to the boundary you need.
45. What is the difference between extends and implements?
A class extends one base class and inherits its implementation. It can implement one or more interfaces to promise a shape without inheriting their runtime behavior.
46. What is tsconfig.json?
tsconfig.json records project compiler options and file selection. The tsc -p . command loads that configuration.
47. What is noEmit?
With noEmit enabled, tsc checks source without writing JavaScript.
48. What are declaration files?
A .d.ts file describes types for JavaScript code without providing its implementation. Packages may ship declarations or use community-maintained @types packages.
49. What is a source map?
A source map links generated JavaScript locations back to source files for debugging tools. Deployment settings determine whether those mappings are available to users.
50. Does TypeScript validate API responses?
No. Treat parsed or network data as unknown, validate its structure at runtime, then use the validated result as a typed value.
TypeScript interview edge cases to explain
These cases show a runtime symptom and the check that addresses it.
| Case | Symptom | Fix |
|---|---|---|
| Incoming JSON | A declared interface provides no runtime check for fields. | Parse as unknown and validate each required field before use. |
| Truthiness check | An empty string or zero follows the same branch as a missing value. | Compare explicitly with the permitted values. |
| Type assertion | A malformed value keeps its original runtime shape. | Check the value or validate its fields before asserting. |
| Readonly reference | Mutation through another reference remains possible. | Use runtime freezing when runtime immutability is required. |
The deliberately incorrect broken-demo.ts produced this compiler diagnostic: broken-demo.ts(2,13): error TS18046: ‘response’ is of type ‘unknown’. Add a guard before reading name, then validate that name is a string.
Conclusion: practice the reasoning
Prepare by answering aloud, then write a small example and say what the compiler can and cannot establish. A concise explanation of narrowing or generic relationships is more useful than memorizing isolated terms.
For background, read the TypeScript explainer and the ts-node unknown-extension fix. The official TypeScript Handbook provides the reference for types, narrowing, and generics.
FAQ
These quick answers address common follow-up questions.
What should I study first for a TypeScript interview?
Start with unions, narrowing, object shapes, and generics, then practice explaining what happens at runtime.
Does TypeScript prevent runtime errors?
No. It checks source types, but external values need runtime validation and programs still need tests.
Is unknown better than any?
Use unknown for values whose type is not yet established because the compiler requires checks before use.




