import { And, If, Not, Or } from "../boolean"; import { Append, Concat, List } from "../list"; import { _IncNonneg } from "../number/int"; import { Cut, Exclude, Select } from "../set"; import { Extends, IsAny, IsNever, Satisfies } from "../type"; import { NumericKey, Required } from "."; /** * tries to append the value corresponding to key `N` to array `A` * @todo detect if it's an optional key and append accordingly */ type TryAppend = `${N}` extends keyof O ? Append : N extends keyof O ? Append : L; /** * given an object with no mapped number types, converts to a list * by iterating from zero and converting the corresponding keys in the object to values in a list. * stops on the first missing key found (i.e. cannot have "gaps" in the object's keys). * does not work with objects with a mapped number type. */ type _AsList = And>, Or, Extends>> extends true ? _AsList, TryAppend, _IncNonneg> : Acc; /** * checks if type `T` maps across the `number` or `\`${number}\`` type */ type IsMappedNumeric = And>, And, Or, Extends<[`${number}`], [T]>>>>; /** * omits all mapped number keys (i.e. `{ [_: number]: whatever }`) from an object. * @todo capture and preserve whether or not keys are optional */ type OmitMappedNumeric = { [K in keyof O as If>, K>]: Required[K]; }; type _MappedValues = number extends keyof O ? Cut[] : O[K][]; type MappedValues = `${number}` extends keyof O ? _MappedValues : number extends keyof O ? O[number][] : []; /** * convert an object into a list * * @since 0.0.2 * * @example * type e0 = AsList<{ 0: boolean, "1": string, 2: number }> // [boolean, string, number] // stringified number keys are recognized * type e1 = AsList<{ 0: boolean, 1: string, 2: number, [x: number]: {} }> // [boolean, string, number, ...{}[]] * type e2 = AsList<{ 0: boolean, 1?: string, 2: number } & { [x: number]: {} }> // [boolean, string | undefined, number, ...{}[]] // optional arguments are converted to * * type e4 = AsList<{ 0: string, 2: number, [x: number]: {} }> // [string, ...number[]] // no gaps are allowed in the keys. while the object has key `2`, since it doesnt have a key `1` the `2` is ignored * * @todo capture optional keys and reflect that in the resultant list, e.g. ideally this should happen: * ```ts * type t1 = AsList<{ 0: boolean, 1: string, 2?: number }> // [boolean, string, number?] // (and in general `T?` gets expanded to `(T | undefined)?`) * type t2 = AsList<{ 0: boolean, 1?: string, 2: number }> // [boolean, string | undefined, number] // optional cannot be before required, but still recognize it's possibly undefined * type t3 = AsList<{ 0: boolean, 1?: string, 2?: number }> // [boolean, string?, number?] // capture _all_ the trailing optional keys * ``` */ export type AsList = Concat, Select, NumericKey>>, List>, MappedValues>; export {}; //# sourceMappingURL=as-list.d.ts.map