Modifizierer gemappter Typen
Modifizierer gemappter Typen ermöglichen in TypeScript die Transformation von Eigenschaften innerhalb eines vorhandenen Typs:
readonlyoder+readonly: Dadurch wird eine Eigenschaft im gemappten Typ schreibgeschützt.-readonly: Dadurch wird eine Eigenschaft im gemappten Typ veränderbar.?: Dadurch wird eine Eigenschaft im gemappten Typ als optional gekennzeichnet.
Beispiele:
type ReadOnly<T> = { readonly [P in keyof T]: T[P] }; // All properties marked as read-only
type Mutable<T> = { -readonly [P in keyof T]: T[P] }; // All properties marked as mutable
type MyPartial<T> = { [P in keyof T]?: T[P] }; // All properties marked as optional