Interview Q&A / TypeScript

INTERVIEW Q&A · 47 QUESTIONS

TypeScript interview questions

Types, interfaces, generics and safe patterns for real codebases.

  1. What are generics in TypeScript and why are they useful?

    Generics let you write a function, class or type that works with many types while still remembering which type was used. Instead of falling back to any, you add a type parameter like T, so the output type is linked to the input type and TypeScript can still check your code.

    BeginnerIn-depth3 min read
  2. What are utility types in TypeScript, such as Partial, Required, Pick, Omit and Record?

    Utility types are built-in generic types that create a new type from an existing one. Partial makes all properties optional, Required makes them all required, Pick keeps only chosen keys, Omit removes chosen keys, and Record builds an object type from a set of keys and a value type.

    BeginnerIn-depth3 min read
  3. What is the difference between interface and type in TypeScript?

    Both describe the shape of data. An interface describes objects and can be extended or merged; a type alias can name any type, including unions, tuples and primitives.

    BeginnerIn-depth2 min read
  4. What is the difference between union and intersection types in TypeScript?

    A union type (A | B) means a value can be one of several types, so you can only use what they have in common until you narrow it. An intersection type (A & B) means a value must be all of the types at once, so it has every property from each.

    BeginnerIn-depth3 min read
  5. What is the difference between unknown and any in TypeScript?

    Both can hold any value. any turns off type checking completely, while unknown forces you to check what the value is before you use it, so it is the safe choice.

    BeginnerIn-depth2 min read