TypeScript Interview Questions
Practice TypeScript questions covering type system, generics, interfaces, utility types, decorators, and advanced type manipulation.
Frequently Asked Questions
What TypeScript topics are tested in interviews?
Core topics include type annotations, interfaces vs types, generics, union and intersection types, type guards, utility types (Partial, Pick, Omit, Record), enums, and module systems. Advanced topics include conditional types, mapped types, template literal types, and declaration merging.
Do I need TypeScript for frontend interviews?
Increasingly yes. Most modern frontend codebases use TypeScript. Companies like Google, Airbnb, and Stripe use TypeScript extensively. Even if not explicitly required, demonstrating TypeScript proficiency in interviews shows attention to code quality and type safety.
What is the difference between interface and type in TypeScript?
Both define object shapes, but interfaces support declaration merging and extends, while types support unions, intersections, and mapped types. Interfaces are preferred for public API contracts and class implementations. Types are better for utility types, unions, and complex type manipulation.
What are TypeScript utility types?
Built-in types that transform other types: Partial<T> makes all properties optional, Required<T> makes them required, Pick<T, K> selects specific properties, Omit<T, K> removes them, Record<K, V> creates mapped types, and ReturnType<T> extracts function return types. Knowing these saves time in interviews.
How do generics work in TypeScript?
Generics allow creating reusable components that work with multiple types while maintaining type safety. They use angle bracket syntax: function identity<T>(arg: T): T. You can constrain generics with extends, set defaults, and use multiple type parameters. They are essential for writing type-safe utility functions.
What are type guards and how are they used?
Type guards narrow types within conditional blocks. Built-in guards include typeof, instanceof, and the in operator. Custom type guards use the 'is' keyword: function isString(x: unknown): x is string. They are important for safely handling union types and unknown values from APIs.