Back to Public Hub
TypeScript
Public

Interview Questions

Updated Mar 28, 2026
Shared by Liubomyr

TypeScript Interview Questions

Comprehensive TypeScript interview questions covering type system, generics, utility types, and best practices:

Fundamentals

1. What is TypeScript?

TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. It adds optional static typing, interfaces, enums, and other features for better tooling and error detection.

2. What are the benefits of TypeScript?

Static typing catches errors at compile time, better IDE support (autocomplete, refactoring), improved code documentation, easier refactoring, enhanced code quality and maintainability.

3. What is the difference between any and unknown?

any: disables type checking, allows any operation. unknown: type-safe version of any, requires type checking before use. Always prefer unknown over any.

4. What is the difference between interface and type?

interface: can be extended, supports declaration merging, better for object shapes. type: more flexible, supports unions/intersections/primitives, cannot be reopened. Use interface for public APIs, type for complex types.

5. What are generics?

Generics create reusable components that work with multiple types. They provide type variables that capture the type provided by the user.

Type System

6. What is type assertion?

Type assertion tells TypeScript to treat a value as a specific type. Syntax: value as Type or <Type>value. Use sparingly as it bypasses type checking.

7. What are type guards?

Type guards narrow the type within a conditional block. Built-in: typeof, instanceof, in operator. Custom: user-defined type predicate functions (value is Type).

8. What is type narrowing?

Type narrowing is TypeScript's process of refining types to more specific types through type guards, equality checks, and control flow analysis.

9. What is never type?

never represents values that never occur. Used for functions that always throw errors or have infinite loops. Also used in exhaustiveness checking.

10. What is void vs never?

void: function returns undefined or nothing. never: function never returns (throws or infinite loop).

Utility Types

11. What is Partial<T>?

Makes all properties of T optional. Useful for update operations where you might only update some fields.

12. What is Pick<T, K>?

Creates a type by picking specific properties K from T. Useful for creating smaller types from larger ones.

13. What is Omit<T, K>?

Creates a type by omitting specific properties K from T. Opposite of Pick.

14. What is Record<K, T>?

Creates an object type with keys of type K and values of type T. Useful for creating dictionaries.

15. What is ReturnType<T>?

Extracts the return type of a function type. Useful when you need to reference a function's return type without redefining it.

Advanced

16. What are conditional types?

Conditional types select one of two possible types based on a condition (T extends U ? X : Y). Enable advanced type transformations.

17. What is keyof?

keyof creates a union of an object type's keys. Useful for creating mapped types and accessing properties safely.

18. What is typeof?

typeof in TypeScript gets the type of a variable or property. Useful for extracting types from values.

19. What are template literal types?

Template literal types build new string literal types from existing ones. Useful for creating typed string patterns.

20. What is the difference between enum and const enum?

enum: generates JavaScript code. const enum: inlined at compile time, no JavaScript generated. const enum is more performant but less flexible.

More in general

Related notes

See all →
TypeScriptgeneral

Advanced Types (Generics & Utility Types)

TypeScript Advanced Types Generics // Generic function function identity<T>(arg: T): T { return arg; } const num = identity<number>(42); // Explicit const str = identity('hello'); // Inferred // Gener…

Mar 3, 2026
View
Same author

More from Liubomyr

See all →
TypeScriptgeneral

Advanced Types (Generics & Utility Types)

TypeScript Advanced Types Generics // Generic function function identity<T>(arg: T): T { return arg; } const num = identity<number>(42); // Explicit const str = identity('hello'); // Inferred // Gener…

Mar 3, 2026
View