TypeScript Course
TypeScript
/
Intermediate

Utility Type Deep Dives

Definition

Interview questions focusing heavily on combining TS built-in utility types to solve complex architectural mapping requirements.

Explain Like I'm New

The interviewer will present a messy API response type and ask you to 'clean it up' using utilities like `Omit`, `Extract`, `NonNullable`, and `ReturnType` without rewriting the interfaces from scratch.

Real World Example

You have a `User` union `type User = Admin | Guest | Member`. The interviewer asks: 'Write a type that extracts ONLY the Admin and Member types, and removes the password field from both'.

Common Use Cases

  • •Refactoring legacy types
  • •Interview screening

Interactive Example

Loading Code Playground...

Interview Questions

basic

  • Combine `Omit` and `ReturnType` in a single statement.

intermediate

  • What is the difference between `Exclude` and `Omit`?

advanced

  • How do you create an `OmitByType` utility?

Flash Cards

Question

Exclude vs Omit?

Click to reveal answer
Answer

`Exclude` operates on UNION types (e.g., extracting 'a' from `'a'|'b'|'c'`). `Omit` operates on OBJECT types (e.g., removing the 'password' key from the `{ name, password }` interface).

Question

What is OmitByType?

Click to reveal answer
Answer

A custom utility that removes properties based on their VALUE type, not their key name. E.g., 'Remove all properties from this object that are booleans'. Uses mapped type remapping: `[K in keyof T as T[K] extends boolean ? never : K]: T[K]`.