Creating Mapped Types
Creating Mapped Types
π¨βπΌ Let's build our own utility types using mapped types!
type Album = {
title: string
year: number
}
type Optional<T> = { [K in keyof T]?: T[K] }
type OptionalAlbum = Optional<Album>
π¨ Open
and:
- Recreate
Partial<T>from scratch - Recreate
Required<T>from scratch - Create a
Nullable<T>that makes all properties nullable - Create a
Mutable<T>that removesreadonly