TypeScript Developer interview questions
100 real questions with model answers and explanations for Junior TypeScript Developer candidates.
See a TypeScript Developer resume example →Practice with flashcards
Spaced repetition · Hunter Pass
Questions
TypeScript is a statically checked language that extends JavaScript with types and compiles to JavaScript.
- Valid JavaScript syntax is generally valid TypeScript syntax, so projects can adopt it gradually.
- The compiler reports many type mistakes before the code runs.
- Browsers and Node.js normally execute the emitted JavaScript, not TypeScript source directly.
Why interviewers ask this: The interviewer checks whether you understand TypeScript as a development-time layer over JavaScript rather than a separate runtime.
Static type checking means TypeScript analyzes value usage before the program runs.
- The compiler compares assignments, arguments, and return values with their declared or inferred types.
- It can reject operations such as calling a string method on a number.
- Static checks reduce a class of mistakes but do not prove that all runtime behavior is correct.
Why interviewers ask this: A strong answer explains both when type checking happens and the limits of what it guarantees.
A type annotation explicitly states the type expected for a variable, parameter, property, or return value.
- A variable annotation appears after its name, as in count: number.
- An annotation lets the compiler reject values that do not match the stated contract.
- Annotations are most useful at boundaries or when inference cannot express the intended type clearly.
Why interviewers ask this: The interviewer evaluates whether you know what annotations do and avoid adding them where inference is already clear.
Type inference lets TypeScript determine a type from the surrounding code without an explicit annotation.
- A variable initialized with 42 is usually inferred as number.
- A function return type can be inferred from the values returned by its branches.
- Inference reduces repetition while preserving compile-time checking.
Why interviewers ask this: The interviewer checks whether you can rely on inference deliberately rather than annotating every value.
Contextual typing infers a value's type from the place where that value is used.
- A callback parameter can be inferred from the method or function receiving the callback.
- An object literal can be checked against the type expected by a variable or argument.
- This context often provides useful types even when the value has no annotations of its own.
Why interviewers ask this: A strong answer recognizes that inference can flow from expected usage, not only from assigned values.
The most common primitive types are string, number, boolean, bigint, symbol, null, and undefined.
- TypeScript uses lowercase names such as string rather than boxed object types such as String.
- JavaScript has one number type for ordinary integer and floating-point values.
- null and undefined require explicit handling when strict null checking is enabled.
Why interviewers ask this: The interviewer checks basic type vocabulary and whether you distinguish primitives from boxed objects.
An array type states the type allowed for each element, using forms such as string[] or Array<string>.
- Both forms describe an array whose elements are strings.
- A union element type such as Array<string | number> allows either member in the same array.
- The element type is checked when values are read, inserted, or passed to array methods.
Why interviewers ask this: The interviewer evaluates whether you can express homogeneous and union-valued collections correctly.
A tuple is an array type with a known length and a specific type for each position.
- A type such as [string, number] requires a string first and a number second.
- A normal number[] can contain any number of numeric elements without position-specific meanings.
- Tuples suit small ordered records, while named object properties are often clearer for larger data.
Why interviewers ask this: A strong answer connects tuple typing to fixed positions and chooses it only when order carries meaning.
An object type describes the property names and value types an object must provide.
- A property such as name: string is required unless it is marked optional.
- Methods can be represented with function-valued properties or method syntax.
- TypeScript checks structural compatibility, so the object's shape matters more than its declared name.
Why interviewers ask this: The interviewer checks whether you understand object shapes and TypeScript's structural type system.
An interface gives a reusable name to an object shape.
- It declares required, optional, readonly, and method members for objects or classes.
- Other interfaces can extend it to add or refine members.
- Values satisfy it by having a compatible structure, without explicitly declaring that relationship.
Why interviewers ask this: A strong answer explains interfaces as reusable structural contracts rather than runtime objects.
A type alias assigns a reusable name to any TypeScript type expression.
- It can name an object shape, union, intersection, tuple, primitive, or function type.
- The alias does not create a new runtime value or a distinct nominal type.
- Type aliases can compose existing types into clearer domain vocabulary.
Why interviewers ask this: The interviewer checks whether you know that aliases can name more than object shapes and disappear at runtime.
Both interface and type can describe object shapes, but they differ in extension and declaration behavior.
- Interfaces extend with extends and can merge when the same interface is declared more than once.
- Type aliases compose with intersections and cannot be reopened by another declaration.
- Type aliases also represent unions and tuples, so consistency and the needed feature usually guide the choice.
Why interviewers ask this: A strong junior answer gives practical differences without claiming that one construct is always better.
Interface extension creates an interface that includes members from one or more parent interfaces.
- The child uses extends and can add its own properties or methods.
- Any redeclared property must remain compatible with the inherited contract.
- Extension is useful for expressing a clear relationship between related object shapes.
Why interviewers ask this: The interviewer evaluates whether you can reuse object contracts without duplicating their members.
A union type represents a value that may be any one of several listed types.
- The vertical bar combines members, as in string | number.
- Before narrowing, code may use only operations safe for every member of the union.
- Unions model alternatives more precisely than weakening the value to any.
Why interviewers ask this: The interviewer checks whether you understand both the flexibility and the safe-operation rule of unions.
An intersection type combines multiple types into one type that must satisfy all of them.
- The ampersand combines members, as in Identified & Timestamped.
- For object types, the result normally contains the required properties from every member.
- Conflicting property requirements can make part or all of an intersection impossible to construct.
Why interviewers ask this: A strong answer explains that intersections require all contracts rather than choosing between them.
A union accepts a value matching at least one member, while an intersection requires a value matching every member.
- string | number represents either a string or a number.
- Named & Auditable represents an object that meets both object contracts.
- Union code usually narrows alternatives, while intersection code can use the combined compatible members.
Why interviewers ask this: The interviewer verifies that you can distinguish alternative shapes from combined requirements.
A literal type represents one exact string, number, or boolean value rather than the wider primitive type.
- A type such as 'pending' accepts only that string value.
- Literal unions can define a closed set such as 'pending' | 'done'.
- Exact values help the compiler catch misspelled or unsupported options.
Why interviewers ask this: The interviewer checks whether you can model finite states more precisely than with a general string.
A const declaration often preserves a primitive literal, while as const keeps literal values throughout an expression.
- A const variable initialized with 'open' can be inferred as the literal type 'open'.
- Object properties normally widen because their values could be reassigned.
- Applying as const keeps nested literal values narrow and marks object properties and tuple elements readonly.
Why interviewers ask this: A strong answer distinguishes a constant variable binding from a const assertion applied to an entire value.
An optional property marked with ? may be absent from an object.
- Reading it usually produces a type that includes undefined.
- Code must check for absence before using it as a definitely present value.
- Optional does not automatically mean the same thing as a required property whose value may be undefined.
Why interviewers ask this: The interviewer checks whether you handle absence safely and understand the difference between missing and present-with-undefined.
readonly prevents a property or collection element from being reassigned through that TypeScript reference.
- A readonly property can be initialized but not later assigned directly.
- ReadonlyArray<T> blocks mutating methods such as push and splice.
- readonly is a compile-time restriction and does not freeze the JavaScript object at runtime.
Why interviewers ask this: A strong answer states both the mutation protection and its compile-time-only limitation.
Locked questions
- 21
What is excess property checking for object literals?
- 22
How do you type function parameters and return values?
- 23
How do optional, default, and rest parameters differ?
resttypes - 24
What does the void return type mean?
- 25
What is the any type, and why should it be used sparingly?
types - 26
What is the unknown type?
types - 27
How are any and unknown different?
- 28
What is the never type?
- 29
How do null and undefined behave with strictNullChecks enabled?
fundamentals - 30
What is type narrowing?
type-narrowing - 31
How does typeof narrow a type?
- 32
How does truthiness narrowing work?
type-narrowing - 33
How does equality narrowing work?
type-narrowing - 34
How does the in operator narrow object unions?
union - 35
How does instanceof narrow a type?
- 36
What is a discriminated union?
uniontype-narrowing - 37
What is a user-defined type predicate?
type-narrowing - 38
What is a type assertion, and how is it different from a type annotation?
- 39
What is a non-null assertion in TypeScript?
typescriptfundamentals - 40
What problem do generics solve in TypeScript?
typescriptgenerics - 41
How does a generic identity function preserve type information?
generics - 42
What is a generic constraint?
generics - 43
Why might a generic function need more than one type parameter?
generics - 44
How can keyof be used with a generic object type?
genericsadvanced-types - 45
What is an enum in TypeScript?
typescriptenums - 46
How do numeric and string enums differ?
- 47
When might a union of string literals be preferable to an enum?
unionenums - 48
What is tsconfig.json used for?
tsconfig - 49
What does the strict option in tsconfig.json do?
tsconfig - 50
Why does TypeScript not replace runtime validation for API data?
validationapitypescript - 51
How would you type a function that formats a user's full name from first and last name?
- 52
How would you type an async function that fetches one user and may return no result?
async - 53
A helper accepts an array of users and a callback that selects a label. How would you type the callback?
callbacks - 54
How would you type an optional page-size parameter while ensuring the function always uses a number internally?
types - 55
How would you type a function that joins any number of string path segments?
joins - 56
A parseId function accepts either a number or a numeric string. How would you type and implement it safely?
- 57
How would you type a React UserCard component with a required user and an optional compact mode?
reactcomponentstypes - 58
TypeScript reports that event.target has no value property in an input change handler. How do you fix it?
typescript - 59
A React state value starts empty and later stores a User. How would you type useState?
reacthooks - 60
How would you type a React layout component that accepts renderable children?
reactcomponents - 61
How would you type an onSelect prop that sends a selected product ID back to a parent component?
components - 62
How would you make a reusable List component preserve the type of each item?
components - 63
A table column should reference a real property of its row type. How would you type the column key?
schema - 64
How would you type a getProperty helper so its return type matches the selected object key?
- 65
How would you type a reusable API result that can carry different data types?
api - 66
A function should accept any value with a length property. How would you constrain its generic type?
generics - 67
TypeScript rejects config[key] while iterating Object.keys(config). How would you fix it?
typescriptiterationconfig - 68
Array.find returns User | undefined, but the next line expects User. How do you fix the error?
fundamentals - 69
document.querySelector may return null. How would you safely update the selected element?
queriesfundamentals - 70
In a catch block the error is unknown. How would you obtain a safe message?
- 71
A value is User | Admin, and only Admin has permissions. How would you access permissions safely?
- 72
After filtering null values, TypeScript still keeps null in the array type. How would you fix the filter?
typescriptfundamentals - 73
How would you render loading, success, and error API states without optional fields everywhere?
types - 74
How would you make a switch over a status union fail type checking when a new status is added?
union - 75
Why can a typeof value === 'object' check still fail when you read object fields, and how do you fix it?
- 76
An API returns either a user object or an object with an error field. How would you distinguish them?
api - 77
How would you write a type guard for an unknown value that should be a User?
type-narrowing - 78
A check if (count) incorrectly treats zero as missing. How would you narrow count: number | undefined?
fundamentals - 79
How would you safely display a city from user.profile.address when each nested field may be absent?
- 80
fetch returns JSON from an external service. How would you keep the response type-safe?
type-safety - 81
How would you type a fetch wrapper that handles both HTTP errors and successful JSON data?
http - 82
The backend sometimes sends avatarUrl: null, but the frontend type says string. How would you fix the mismatch?
fundamentals - 83
An API uses snake_case fields but the app uses camelCase. How would you type the conversion?
api - 84
How would you type a PATCH request that may update only some User fields?
- 85
How would you create a public user type that excludes passwordHash and internal notes?
passwords - 86
How would you type a label map that must contain every OrderStatus value?
- 87
Generated OpenAPI types no longer match the deployed API. What would you do?
openapideployment - 88
How would you type a React form submit handler and read its input values safely?
reactforms - 89
How would you type a React ref for an input that is not mounted initially?
react - 90
A React context defaults to null. How would you prevent every consumer from forgetting the null check?
reactfundamentals - 91
How would you type a reusable form field whose name must be a key of the form values?
forms - 92
How would you type reducer actions so each action carries the correct payload?
- 93
TypeScript infers {} for a reduce accumulator used to group users by role. How would you fix it?
typescriptadvanced-types - 94
How would you preserve individual result types when awaiting several different promises together?
asyncpromises - 95
JSON.parse can produce any shape. How would you safely load application settings from localStorage?
- 96
A JavaScript package has no type declarations. How would you integrate it without making the whole feature any?
javascript - 97
A third-party type says a value is always string, but runtime logs show null. How would you handle it?
dependenciesfundamentals - 98
How would you type a fixed set of theme names without using a broad string?
- 99
A component call has a misspelled prop, but an assertion makes the error disappear. How would you fix it?
components - 100
You receive a TypeScript error in unfamiliar code. What steps do you take before adding a cast?
typescript