import type {Simplify} from './simplify'; // Returns `never` if the key is optional otherwise return the key type. type RequiredFilter = undefined extends Type[Key] ? Type[Key] extends undefined ? Key : never : Key; // Returns `never` if the key is required otherwise return the key type. type OptionalFilter = undefined extends Type[Key] ? Type[Key] extends undefined ? never : Key : never; /** Enforce optional keys (by adding the `?` operator) for keys that have a union with `undefined`. @example ``` import type {EnforceOptional} from 'type-fest'; type Foo = { a: string; b?: string; c: undefined; d: number | undefined; }; type FooBar = EnforceOptional; // => { // a: string; // b?: string; // c: undefined; // d?: number; // } ``` @internal @category Object */ export type EnforceOptional = Simplify<{ [Key in keyof ObjectType as RequiredFilter]: ObjectType[Key] } & { [Key in keyof ObjectType as OptionalFilter]?: Exclude }>;