Complete the code to define a mapped type that makes all properties of T optional.
type PartialType<T> = { [K in keyof T]?: T[K] };The ?: syntax makes each property optional in a mapped type.
Complete the code to recursively make all nested properties of T optional.
type DeepPartial<T> = { [K in keyof T]?: T[K] extends object ? [1] : T[K] };Using DeepPartial<T[K]> recursively applies the partial transformation to nested objects.
Fix the error in the code to correctly check if T[K] is an object but not null or array.
type DeepPartial<T> = { [K in keyof T]?: T[K] extends object ? (T[K] extends [1] ? T[K] : DeepPartial<T[K]>) : T[K] };The check T[K] extends null | any[] excludes null and arrays from recursive partial application.
Fill both blanks to create a mapped type that makes all properties readonly and deeply readonly.
type DeepReadonly<T> = { [1] [K in keyof T][2]: T[K] extends object ? DeepReadonly<T[K]> : T[K] };The readonly keyword before the property makes it readonly, and ? after the property name makes it optional if desired.
Fill all three blanks to create a mapped type that transforms all string properties to uppercase strings recursively.
type DeepUppercase<T> = { [K in keyof T]: T[K] extends string ? [1] : T[K] extends object ? [2] : T[K] };Uppercase<T[K]> converts string literals to uppercase, and DeepUppercase<T[K]> applies the transformation recursively to nested objects.