Transform existing types by applying operations to each property. Useful for adding prefixes/suffixes to properties, creating key-value pairs from objects, etc.
interface User {
name: string;
age: number;
}
type ReadOnly<T> = { readonly [P in keyof T]: T[P] };
const readOnlyUser: ReadOnly<User> = {
name: 'Kurt',
age: 27
};
// readOnlyUser.name = 'Chester';
// Error: Cannot assign to 'name' because it is a read-only property
Useful for manipulate and transform data from the API or before passing data to another component, with different data types.
➖➖➖➖➖➖
#TypeScript



