import type { Prettify } from './typescript'; /** * Lol Typescript * https://stackoverflow.com/questions/49927523/disallow-call-with-any/49928360#49928360 */ type IfAny = 0 extends 1 & T ? Y : N; type OptionalFieldsOnly = { [K in keyof T as T[K] extends Required[K] ? IfAny : K]: T[K]; }; type RequiredFieldsOnly = { [K in keyof T as T[K] extends Required[K] ? IfAny : never]: T[K]; }; type Enforced = { [K in keyof T]-?: T[K]; }; type AndUndefined = { [K in keyof T]: T[K] | undefined; }; /** * Enforce that all optional fields are undefined * @example * type Foo = { a: string, b?: number } * type Bar = EnforcePartials // { a: string, b: number | undefined } */ export type EnforcePartials = Prettify>> & RequiredFieldsOnly>; export {};