// Created on savesnippets.com ยท https://savesnippets.com/6ZdcmS23Yqcwe3 type User = { id: string; name: string; email: string }; // Deep readonly (recursive) type DeepReadonly = { readonly [K in keyof T]: T[K] extends object ? DeepReadonly : T[K]; }; // Mutable inverse of Readonly type Mutable = { -readonly [K in keyof T]: T[K] }; // Keep only the keys whose value matches a type type KeysOfType = { [K in keyof T]: T[K] extends V ? K : never }[keyof T]; type StringKeys = KeysOfType; // 'id' | 'name' | 'email' // Make some keys optional (the others stay required) type PartialBy = Omit & Partial>; type NewUser = PartialBy; // { name: string; email: string; id?: string }