The original object type.
The keys within T that should be made optional.
type User = {
id: string;
name: string;
email: string;
};
type Result = MakeOptional<User, 'email'>;
// {
// id: string;
// name: string;
// email?: string;
// }
type Config = {
host?: string;
port: number;
secure: boolean;
};
type Result = MakeOptional<Config, 'secure'>;
// {
// host?: string;
// port: number;
// secure?: boolean;
// }
Constructs a new type from
Twhere the specified keysKbecome optional, while all other keys preserve their original modifiers.Unlike the naive
Omit<T, K> & Partial<Pick<T, K>>form, this version also preserves keys that were already optional inT, which makes it safer for exact type-equality tests and library-grade type transforms.