Interviewers probe TypeScript knowledge to assess a candidate's ability to write robust, maintainable, and scalable JavaScript applications. They look for understanding of type safety, advanced type manipulation, and how TypeScript enhances developer experience and prevents common runtime errors.
15 questions (5 easy · 6 medium · 4 hard), each with what a strong answer covers and where people lose the point. Free to read, no account.
1.Explain the difference between the `any` and `unknown` types in TypeScript. When would you use one over the other?
Warm-up
What a strong answer covers
Define `any` as a type that opts out of all type checking, allowing any operation without compile-time errors.
Define `unknown` as a type-safe counterpart to `any`, requiring type narrowing before performing operations.
Explain that `unknown` forces developers to explicitly check or assert the type before use, preventing potential runtime errors.
Provide scenarios where `any` might be used (e.g., quick migration, third-party libraries without types) and `unknown` is preferred (e.g., API responses, user input).
Where people lose the point
×Failing to mention that `unknown` requires type narrowing.
×Suggesting `any` is always a good default when types are uncertain.
×Not highlighting the safety benefits of `unknown` over `any`.
2.What are the key differences between an `interface` and a `type` alias in TypeScript? When would you choose one over the other?
Warm-up
What a strong answer covers
Explain that `interface` is primarily for defining object shapes and class contracts, supporting declaration merging.
Explain that `type` aliases can name any type, including primitives, unions, intersections, and object shapes, but do not support declaration merging.
Discuss `extends` and `implements` keywords: interfaces can extend other interfaces and be implemented by classes; type aliases can use intersection types for similar extension.
Provide common use cases: interfaces for library/API definitions and class contracts, type aliases for complex union/intersection types or naming primitives.
Where people lose the point
×Incorrectly stating that type aliases can be implemented by classes directly.
×Forgetting to mention declaration merging as a unique feature of interfaces.
×Not providing clear scenarios for when to prefer one over the other.
6.What are TypeScript declaration files (`.d.ts`) and why are they important for working with JavaScript libraries?
Core
What a strong answer covers
Define `.d.ts` files as files that contain only type declarations, without any implementation code.
Explain their purpose: to provide type information for existing JavaScript code or libraries, allowing TypeScript projects to use them with type safety.
Discuss how they enable TypeScript's compiler and IDEs to understand the shape of JavaScript modules, functions, and objects.
Highlight their importance for interoperability, tooling support (autocompletion, error checking), and maintaining type safety when integrating with untyped JavaScript.
7.What is `strict` mode in TypeScript and why is it highly recommended for new projects?
Core
What a strong answer covers
Explain that `strict` mode is a configuration option (`"strict": true` in `tsconfig.json`) that enables a suite of stricter type-checking options.
List some key options enabled by `strict`: `noImplicitAny`, `strictNullChecks`, `strictFunctionTypes`, `strictPropertyInitialization`, `noImplicitThis`, `alwaysStrict`.
Discuss the benefits: catching more potential errors at compile time, improving code robustness, enhancing maintainability, and promoting better coding practices.
Emphasize that it leads to more predictable and safer code, reducing runtime bugs, especially in larger codebases.
Where people lose the point
×Only mentioning one or two strict options without explaining the overall benefit.
×Downplaying the importance of `strictNullChecks`.
×Not connecting strict mode to improved code quality and fewer runtime errors.
9.Describe conditional types in TypeScript. How do they enable advanced type manipulation, and when would you use them?
Hard
What a strong answer covers
Define conditional types as types that select one of two possible types based on a condition, using the form `T extends U ? X : Y`.
Explain how they allow for type-level logic, enabling types to be determined dynamically based on other types.
Provide an example, such as `Exclude<T, U>` (a built-in utility type that uses conditional types) or a custom type that extracts properties based on their type.
Discuss use cases like filtering properties, extracting return types of functions, or creating complex type transformations in libraries.
Where people lose the point
×Not clearly explaining the `extends` keyword's role in the condition.
×Providing an example that doesn't clearly demonstrate the conditional logic.
×Failing to connect conditional types to their power in advanced type manipulation and library authoring.
10.When would you use decorators in TypeScript? Provide a simple example of a class or method decorator.
Hard
What a strong answer covers
Define decorators as special kinds of declarations that can be attached to classes, methods, accessors, properties, or parameters.
Explain their purpose: to add metadata, modify behavior, or wrap existing code without changing its structure, often used for metaprogramming.
Mention common use cases: dependency injection frameworks (e.g., Angular), ORMs (e.g., TypeORM), logging, authentication, or validation.
Provide a simple example of a class decorator (e.g., adding a property) or a method decorator (e.g., logging method calls), explaining its syntax and effect.
Where people lose the point
×Confusing decorators with higher-order functions or other design patterns.
×Providing an example that is overly complex or syntactically incorrect.
×Not explaining that decorators are an experimental feature and require specific `tsconfig.json` settings.
12.How do you define optional properties in an interface or type alias in TypeScript? What are the implications of using them?
Warm-up
What a strong answer covers
Explain that optional properties are defined using a `?` suffix after the property name (e.g., `name?: string`).
Discuss the implication that an optional property might be `undefined` at runtime.
Explain that TypeScript will enforce checks for `undefined` when `strictNullChecks` is enabled, requiring explicit handling (e.g., optional chaining, nullish coalescing, type guards).
Provide an example of an interface or type alias with an optional property and demonstrate how to safely access it.
Where people lose the point
×Forgetting to mention the `?` syntax.
×Not discussing the interaction with `strictNullChecks`.
×Failing to show how to safely access an optional property.
13.How does TypeScript infer types? Provide examples of implicit and explicit typing and discuss when to prefer one over the other.
Core
What a strong answer covers
Explain type inference as TypeScript's ability to automatically determine the type of a variable, function return, or expression based on its initial value or usage.
Provide an example of implicit typing (e.g., `let x = 10;` where `x` is inferred as `number`).
Provide an example of explicit typing (e.g., `let y: string = 'hello';`).
Discuss when to prefer implicit typing (for simple, obvious cases to reduce verbosity) and explicit typing (for clarity, preventing incorrect inference, or when initializing later).
Where people lose the point
×Confusing type inference with `any`.
×Not providing clear examples for both implicit and explicit typing.
×Failing to explain the trade-offs between verbosity and clarity.
14.Explain the `infer` keyword in TypeScript. How is it used within conditional types to extract types?
Hard
What a strong answer covers
Define `infer` as a keyword used within the `extends` clause of a conditional type to declare a new type variable.
Explain its purpose: to 'capture' or 'extract' a type from a type being checked, making that extracted type available for use in the true branch of the conditional type.
Provide a concrete example, such as `ReturnType<T>` (a built-in utility type) or a custom type that extracts the type of elements from an array.
Demonstrate how `infer` allows for powerful type transformations by dynamically determining parts of a type.
Where people lose the point
×Misunderstanding that `infer` can only be used in the `extends` clause of a conditional type.
×Providing an example that doesn't clearly show type extraction.
×Failing to explain *why* `infer` is necessary for such extractions.
15.When would you use an `enum` in TypeScript? What are its advantages and potential drawbacks?
Warm-up
What a strong answer covers
Define `enum` as a way to define a set of named constants, making code more readable and maintainable.
Explain its primary use case: representing a fixed set of related values, such as days of the week, status codes, or user roles.
Discuss advantages: improved readability, type safety (compiler checks for valid enum members), and self-documenting code.
Discuss potential drawbacks: enums add runtime overhead (they compile to JavaScript objects), and string enums can be more verbose than union types of string literals.
Where people lose the point
×Not mentioning that enums compile to JavaScript objects.
×Failing to discuss the alternative of using union types of string literals.
×Overstating the performance impact or understating the readability benefits.
A question a TypeScript panel actually asks, answered out loud, scored on what you said and how you said it. Under two minutes, and nothing to sign up for.
“Explain the difference between the `any` and `unknown` types in TypeScript. When would you use one over the other?”
We never store the audio. Your answer is deleted within 24 hours unless you save the result.
How TypeScript answers get judged
The weights a TypeScript interviewer is holding, whether or not they say so out loud. Round Zero scores your practice answers against exactly these, and quotes your own words back as the evidence for each.
Correctness and Accuracy
40%
The answer demonstrates a precise and accurate understanding of TypeScript concepts, syntax, and best practices. No factual errors or misunderstandings.
Conceptual Depth and Nuance
30%
The answer goes beyond surface-level definitions, explaining the 'why' behind concepts, discussing trade-offs, edge cases, and advanced implications.
Problem-Solving and Practical Application
20%
The candidate effectively applies concepts to practical scenarios, provides relevant code examples, and discusses real-world use cases and implications.
Clarity and Communication
10%
The explanation is clear, concise, well-structured, and easy to understand. Technical terms are used appropriately, and examples are illustrative.
You have read what strong TypeScript answers contain. The next thing that moves the needle is producing one under time, out loud, and finding out where it falls apart.
What TypeScript interview questions should I practice?
Start with the core areas TypeScript interviewers probe: Explain the difference between the `any` and `unknown` types in TypeScript. When would you use one over the other; What are the key differences between an `interface` and a `type` alias in TypeScript? When would you choose one over the other; Provide an example of a generic function in TypeScript and explain how generics improve code reusability and type safety.. This page outlines strong answers and common mistakes, and the scored path drills each one with follow-ups.
Is the TypeScript practice free?
Yes. The TypeScript path runs free inside Round Zero: lessons, practice questions and flashcards. Drills are unlimited on every plan, free included. So is the full scorecard. Free also covers 3 complete scored interviews, no card.
How is this different from a TypeScript question list?
A static list gives you questions with no feedback. Round Zero runs a live scored practice that probes your actual answers, rotates difficulty, and tells you exactly what to fix, grounded in a TypeScript rubric.
How should I prepare for a TypeScript interview?
Learn the concepts, drill the questions until answers come fast, then prove it in a scored mock. Round Zero sequences all three so you know you are ready, not just that you read about TypeScript.
How is a TypeScript answer scored?
TypeScript answers are scored on correctness and accuracy, conceptual depth and nuance, problem-solving and practical application, clarity and communication, with evidence quoted from what you actually said, so feedback is specific instead of generic praise.
More free tools
Try everything. Sign up only when you want the full version.