export type ExtractEqual = ( A extends B ? Extract : never ); /* type a = ExtractEqual; type b = ExtractEqual<3|2|1, 1|2>; //This doesn't work because number|1 is just number type c = ExtractEqual; //*/ //TODO-DEBATE Better name or sth export type ToUnknownIfAllFieldsNever = ( T[keyof T] extends never ? unknown : T[keyof T] ); export type Writable = { -readonly [k in keyof T] : Writable }; export function isObjectWithKeys ( raw : any, keys : Extract[] ) : raw is { [k in Extract] : any } { if (raw == undefined) { return false; } if (!(raw instanceof Object)) { return false; } for (let k of keys) { if (!(k in raw)) { return false; } } return true; } export type MAX_SAFE_INTEGER = 9007199254740991; export const MAX_SAFE_INTEGER : MAX_SAFE_INTEGER = 9007199254740991; export type Omit = Pick> export function isStringArray (raw : any) : raw is string[] { if (!(raw instanceof Array)) { return false; } for (let item of raw) { if (typeof item != "string") { return false; } } return true; } export type PromiseResult

> = ( P extends Promise ? R : never ); /* Getters are a good way to pretend that a function is a read-only variable. They also help with resolving circular imports during run-time. */ export function lazyInit ( key : K, instantiate : () => T ) : { [k in K] : T } { let value : T|undefined = undefined; const result = { get [key] () : T { if (value == undefined) { value = instantiate(); } return value; } }; return result as any; } export type UnionToIntersection = ( ( U extends any ? (k: U) => void : never ) extends ( (k: infer I) => void ) ? I : never ); export type IsStrictSameType = (() => A extends A1 ? true : false) extends (() => A extends A2 ? true : false) ? true : false ; export type ExtractStrictSameType< A1, A2 > = A1 extends any ? ( IsStrictSameType extends true ? A1 : never ) : never ; /** * https://github.com/microsoft/TypeScript/issues/32707#issuecomment-521819804 * * @todo Support both `A1` and `A2` being union types * At the moment, it only works right if `A2` is not a union */ export type TryReuseExistingType< A1, A2 > = ExtractStrictSameType extends never ? //Could not reuse anything in `A1` A2 : //We can reuse something in `A1` ExtractStrictSameType ;