Makes specified keys K optional in each member of a union T.
K
T
This distributes over unions, ensuring each member is processed individually. Only keys that exist in each member are affected.
The target type (can be a union)
Keys to make optional (defaults to all union keys)
type Result = MakeOptional<{ a: string; b: number }>;// ^?// { a?: string; b?: number } Copy
type Result = MakeOptional<{ a: string; b: number }>;// ^?// { a?: string; b?: number }
type Result = MakeOptional<{ a: string } | { b: number }>;// ^?// { a?: string } | { b?: number } Copy
type Result = MakeOptional<{ a: string } | { b: number }>;// ^?// { a?: string } | { b?: number }
type Result = MakeOptional<{ a: string } | { b: number }, "a">;// ^?// { a?: string } | { b: number } Copy
type Result = MakeOptional<{ a: string } | { b: number }, "a">;// ^?// { a?: string } | { b: number }
Makes specified keys
Koptional in each member of a unionT.This distributes over unions, ensuring each member is processed individually. Only keys that exist in each member are affected.