export type Schema = { type: 'boolean' | 'number' | 'string' | 'array' | 'object' | 'any'; nullable: boolean; optional: boolean; items?: Schema; properties?: Obj; description?: string; example?: any; format?: string; ref?: string; enum?: string[]; }; type NonUndefinedPropertyNames = { [K in keyof T]: T[K]['optional'] extends true ? never : K }[keyof T]; type UndefinedPropertyNames = { [K in keyof T]: T[K]['optional'] extends true ? K : never }[keyof T]; type OnlyRequired = Pick>; type OnlyOptional = Pick>; export type Obj = { [key: string]: Schema }; export type ObjType = { [P in keyof OnlyOptional]?: SchemaType } & { [P in keyof OnlyRequired]: SchemaType }; // https://qiita.com/hrsh7th@github/items/84e8968c3601009cdcf2 type MyType = { 0: any; 1: SchemaType; }[T extends Schema ? 1 : 0]; type NullOrUndefined

= p['nullable'] extends true ? p['optional'] extends true ? (T | null | undefined) : (T | null) : p['optional'] extends true ? (T | undefined) : T; export type SchemaType

= p['type'] extends 'number' ? NullOrUndefined : p['type'] extends 'string' ? NullOrUndefined : p['type'] extends 'boolean' ? NullOrUndefined : p['type'] extends 'array' ? NullOrUndefined>[]> : p['type'] extends 'object' ? NullOrUndefined>> : p['type'] extends 'any' ? NullOrUndefined : any;