/* Jovian (c) 2020, License: MIT */ import { promise } from "./common/globals.ix"; export type PartialAny = { [P in keyof T]?: any; }; export type PartialCustom = { [P in keyof T]?: S; }; export type PartialCustomWith = PartialCustom & A; export type FullCustom = { [P in keyof T]: S; }; export type FullRequire = { [P in keyof T]: T[P]; }; export type HasNoExtraProp = (keyof Base | keyof Operand) extends keyof Base ? keyof Base extends (keyof Base | keyof Operand) ? 'true' : 'false' : 'false' export type GetFormerIfNoExtraProp = HasNoExtraProp extends 'true' ? Base : Impossible; export type GetLatterIfNoExtraProp = HasNoExtraProp extends 'true' ? Operand : Impossible; export interface PartialSettings { settings?: any; } export type Intersect = { [P in keyof A & keyof B]: A[P] | B[P]; } export type Impossible = { [P in K]: never; }; export type NoExtra = U & Impossible>; export type RequireProp = Omit & { [MK in K]-?: NonNullable }; // tslint:disable-next-line: callable-types export interface Class { new (...args): T; name: string; } export type ClassStaticTemplate = Class & StaticTemplate; // tslint:disable-next-line: callable-types export interface InitiableClass { new (init: Partial, ...args): T; name: string; } // https://stackoverflow.com/a/58715632 export type Unshift = ((arg: H, ...argN: T) => void) extends ((...r: infer R) => void) ? R : never; export type Push = Unshift extends infer A ? { [K in keyof A]: K extends keyof T ? T[K] : V } : never; export type AddFunctionArg any, ExtraParam> = (...args: Extract, ExtraParam>, readonly any[]>) => ReturnType; // https://stackoverflow.com/a/54986490 export function autoImplement(): new () => T { return class { } as any; } // tslint:disable-next-line: class-name export class _ { a = 0; } // tslint:disable-next-line: max-line-length export type TypedSpreader = A1 extends _ ? [] : A2 extends _ ? [A1] : A3 extends _ ? [A1, A2] : A4 extends _ ? [A1, A2, A3] : A5 extends _ ? [A1, A2, A3, A4] : A6 extends _ ? [A1, A2, A3, A4, A5] : A7 extends _ ? [A1, A2, A3, A4, A5, A6] : A8 extends _ ? [A1, A2, A3, A4, A5, A6, A7] : A9 extends _ ? [A1, A2, A3, A4, A5, A6, A7, A8] : A10 extends _ ? [A1, A2, A3, A4, A5, A6, A7, A8, A9] : A11 extends _ ? [A1, A2, A3, A4, A5, A6, A7, A8, A9, A10] : A12 extends _ ? [A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11] : A13 extends _ ? [A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12] : A14 extends _ ? [A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13] : A15 extends _ ? [A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14] : A16 extends _ ? [A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15] : END extends _ ? [A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15, A16] : any[]; export type MergeClass = { [U in (keyof Source | keyof NewProps)]: U extends keyof NewProps ? NewProps[U] : U extends keyof Source ? Source[U] : string; } export type MergeClassPartial = { [U in (keyof Source | keyof NewProps)]?: U extends keyof NewProps ? NewProps[U] : U extends keyof Source ? Source[U] : string; } export type PromiseCollapse = A0 extends Promise>>>> ? X : A0 extends Promise>>> ? X : A0 extends Promise>> ? X : A0 extends Promise> ? X : A0 extends Promise ? X : A0; export type TaggedTemplateSelfChain = T & ((strArr: TemplateStringsArray, ...args: S) => TaggedTemplateSelfChain); export function punchGrab(res: T): PromiseCollapse { return promise(async (resolve, reject) => { try { while ((res as any)?.then) { (res as any) = await res; } return resolve(res); } catch (e) { return reject(e); } }) as any; } export type configBoolean = true | false | 1 | 0; export type configTrue = true | 1; export type configFalse = false | 0; export function as(v?: any) { return v as T; } type RequiredType = boolean | Class; export const required: RequiredType = true;