← ALL GUIDES

INTERVIEW PREP · TYPESCRIPT

TypeScript Interview Questions & Answers

TypeScript questions look easy until the interviewer asks why. These answers carry the why.

THE QUESTIONS

Real questions, senior answers

  1. 01

    What is a generic function in TypeScript?

    A function that takes type arguments alongside value arguments — type-flexible code without falling back to any.

    Declare function myFn<T>(param: T) and the caller fixes T at use time: myFn<number>(...) makes anything but a number a compile error. Use generics when the type is only known by the caller.

    GenericsType arguments
  2. 02

    What does 'as const' do, and how is it different from Object.freeze?

    as const makes an object literal deeply read-only at the type level — every nested property becomes immutable to the compiler. Perfect for config objects nobody should mutate.

    Object.freeze is the runtime cousin, but it's shallow (first level only) and does nothing at build time. as const is compile-time only — it won't stop code that's already running.

    as constImmutabilityBuild time vs runtime
  3. 03

    What does the private access modifier do?

    It makes a class member accessible only inside the class — instances can't reach it from outside, and TypeScript errors if they try.

    It's interface segregation in practice: expose exactly what consumers of the class need, nothing more.

    Access modifiersEncapsulationSOLID
  4. 04

    What is a decorator, and when would you use one?

    A function that wraps a class or method to add shared behavior — @Injectable() in NestJS or Angular is the classic case.

    It's the decorator pattern: composition over inheritance. Reusing behavior through long inheritance chains violates Liskov substitution sooner or later; decorating avoids the chain entirely.

    DecoratorsNestJSComposition over inheritance
  5. 05

    type vs interface — what's the difference, and when do you use each?

    Mostly interchangeable, with one real difference: interfaces merge. Declare the same interface twice and TypeScript combines them; types must be unique.

    That makes interfaces right for anything consumers might extend — like Express's Request. A practical split: types for your domain entities, interfaces for auxiliary shapes like component props.

    Declaration mergingDomain modeling
  6. 06

    What is a type guard?

    A function that narrows a union type: given type Fruit = Pineapple | Apple | Strawberry, an isPineapple() guard tells the compiler which member you're holding.

    Use one whenever you need to do something specific with one member of a union.

    Type narrowingUnion types
  7. 07

    Structural vs nominal typing — which does TypeScript use?

    Structural. If two objects have the same shape, TypeScript treats them as the same type.

    Java and C# are nominal: same properties mean nothing unless the objects share the declared class. Structural typing gives TypeScript its flexibility — objects are interchangeable when they satisfy the same shape.

    Structural typingType compatibility
A preview of the free Senior training

Free Senior Training.

One session, the whole system: the fundamentals, the interview strategy, and the plan to the offer. Watch it free.