Flashcard Deck · 21 cards · Public

TypeScript - Advanced Types & Interfaces

Master advanced TypeScript concepts including conditional types, mapped types, utility types, and discriminated unions to write type-safe, scalable code.

Cards in this deck

(21 cards)

Preview terms and definitions before starting your study session.

#1
Term
Interface vs. Type: Declaration Merging
Definition
An interface can be declared multiple times with the same name, and TypeScript will automatically merge their definitions together. A type alias cannot be redeclared once defined; attempting to do so will trigger a compile-time error.
#2
Term
Interface vs. Type: Syntax & Extensibility
Definition
interface extends other structures using the extends keyword (e.g., interface B extends A {}). A type alias extends other types using intersection operators (e.g., type B = A & { ... }). Unlike interfaces, type aliases can also directly represent primitives, unions, and tuples.
#3
Term
Utility Type: Partial<T>
Definition
Partial<T> constructs a type with all properties of T set to optional.
Under the hood:
typescript3 lines
type Partial<T> = {
  [P in keyof T]?: T[P];
};
#4
Term
Utility Type: Required<T>
Definition
Required<T> constructs a type with all properties of T set to required. It explicitly removes the optional modifier using -?.
Under the hood:
typescript3 lines
type Required<T> = {
  [P in keyof T]-?: T[P];
};
#5
Term
Utility Type: Readonly<T>
Definition
Readonly<T> constructs a type with all properties of T set to readonly. Reassigning properties of an object typed with Readonly<T> will cause a compile-time error.
#6
Term
Utility Type: Pick<T, K>
Definition
Pick<T, K> constructs a type by selecting a specified set of keys K from object type T.
Example:
typescript6 lines
interface User {
  id: number;
  name: string;
  email: string;
}
type UserSummary = Pick<User, 'id' | 'name'>;
#7
Term
Utility Type: Omit<T, K>
Definition
Omit<T, K> constructs a type with all properties of T except those listed in K.
Example:
typescript6 lines
interface User {
  id: number;
  name: string;
  passwordHash: string;
}
type PublicUser = Omit<User, 'passwordHash'>;
#8
Term
Utility Type: Record<K, T>
Definition
Record<K, T> constructs an object type whose property keys are K and whose property values are T. It maps a set of string or numeric literal keys to another type.
Example:
typescript2 lines
type Role = 'admin' | 'user';
type Permissions = Record<Role, string[]>;
Showing 8 of 21 cards in this deck.
Study All Now

Related Flashcard Sets

Explore similar study materials created by the community

Browse community decks