Flashcard Deck · 20 cards · Public

TypeScript - Advanced Type Systems & Utility Types

Master advanced TypeScript features including generics, conditional types, mapped types, and utility types to build flexible and type-safe applications.

Cards in this deck

(20 cards)

Preview terms and definitions before starting your study session.

#1
Term
Generics in TypeScript (<T>)
Definition
Reusable type templates that allow functions, classes, or interfaces to work across various types while maintaining strict type safety.
typescript3 lines
function identity<T>(arg: T): T {
  return arg;
}
#2
Term
Type Alias (type) vs. Interface (interface)
Definition
interface is optimized for defining object shapes and supports declaration merging (adding properties by re-declaring the interface).
type is more flexible; it can represent primitives, unions (|), intersections (&), and tuples, but cannot be reopened for declaration merging.
#3
Term
Discriminated Unions
Definition
A pattern that combines union types with a single common literal property (the discriminant) to allow TypeScript to narrow down the specific type in switch or if statements.
typescript3 lines
type Shape =
  | { kind: "square"; size: number }
  | { kind: "circle"; radius: number };
#4
Term
Utility Type: Partial<T>
Definition
Constructs a type with all properties of T set to optional (?).
Implementation:
typescript3 lines
type Partial<T> = {
  [P in keyof T]?: T[P];
};
#5
Term
Utility Type: Required<T>
Definition
Constructs a type with all properties of T set to required by removing optional modifiers using -?.
Implementation:
typescript3 lines
type Required<T> = {
  [P in keyof T]-?: T[P];
};
#6
Term
Utility Type: Readonly<T>
Definition
Constructs a type with all properties of T set to readonly, preventing property reassignment after initialization.
typescript1 line
type ImmutableUser = Readonly<{ name: string; age: number }>;
#7
Term
Utility Type: Pick<T, K>
Definition
Constructs a type by selecting a specific set of keys K from object type T.
typescript1 line
type UserPreview = Pick<User, "id" | "name">;
#8
Term
Utility Type: Omit<T, K>
Definition
Constructs a type with all properties of T except those specified in key union K.
typescript1 line
type UserWithoutPassword = Omit<User, "password">;
Showing 8 of 20 cards in this deck.
Study All Now

Related Flashcard Sets

Explore similar study materials created by the community

Browse community decks