import { Builtin } from "../built-in"; import { IsAny } from "../is-any"; import { IsNever } from "../is-never"; import { CreateTypeOptions } from "../create-type-options"; import { ValueOf } from "../value-of"; type Pathable = string | number; type NonRecursiveType = Builtin | Promise | ReadonlyMap | ReadonlySet; type DefaultRecursivePathsOptions = { depth: []; }; /** * @param depth This option counts the number of recursive calls in * `RecursivePathsOptions['depth']['length']`. Used in combination with * `PathsOptions['depth']` */ type RecursivePathsOptions = { depth: any[]; }; /** * @param depth By default, the depth option is set to 7. It should cover the * majority of use cases. If by any chance it doesn't fit you, feel free to * increase the value. However, this may increase the chance of getting * `Type instantiation is excessively deep and possibly infinite` error. * * @param anyArrayIndexAccessor By default there is no wildcard access to * array indices - usage must be intentionally configured. */ type DefaultPathsOptions = { depth: 7; anyArrayIndexAccessor: `${number}`; }; /** * @param depth This option restricts the depth of the paths lookup and removes `Type * instantiation is excessively deep and possibly infinite` errors for * potentially infinite types. * * @param anyArrayIndexAccessor This wildcard will satisfy any array index if defined. */ type PathsOptions = { depth: number; anyArrayIndexAccessor: string; }; type Append = [...Tuple, 0]; type RecursivePaths, CallOptions extends RecursivePathsOptions> = IsNever extends true ? never : NonNullable}` | (CallOptions["depth"]["length"] extends UserOptions["depth"] ? never : Type[Key] extends infer Value ? Value extends Value ? HasParsablePath extends true ? RecursivePaths; }> extends infer Rest ? IsNever extends true ? never : Rest extends Pathable ? `${AnyArrayIndexAccessorOrKey}.${Rest}` : never : never : never : never : never) : never; }>>; type HasParsablePath = Type extends NonRecursiveType ? false : IsAny extends true ? false : Type extends object ? true : false; type UnsafePaths> = Type extends Type ? HasParsablePath extends true ? RecursivePaths : never : never; type AnyArrayIndexAccessorOrKey> = Key extends number ? Key | UserOptions["anyArrayIndexAccessor"] : Key; export type Paths = {}> = UnsafePaths>; export {};