import { IterationOf } from '../Iteration/IterationOf'; import { Iteration } from '../Iteration/Iteration'; import { Next } from '../Iteration/Next'; import { Pos } from '../Iteration/Pos'; import { At } from '../Any/At'; import { Cast } from '../Any/Cast'; import { NonNullable } from '../Union/NonNullable'; import { Update } from '../List/Update'; import { Key } from '../Iteration/Key'; import { Key as AKey } from '../Any/Key'; import { List } from '../List/List'; import { Length } from '../List/Length'; import { Extends } from '../Any/Extends'; /** * @hidden */ declare type ValidatePath, I extends Iteration> = Update, [ At]> ] extends [never] ? keyof O : Path[Pos]>; /** * @hidden */ declare type __ValidPath, I extends Iteration = IterationOf<0>> = { 0: __ValidPath]>>, ValidatePath, Next>; 1: Path; }[Extends, Length>]; /** * @hidden */ export declare type _ValidPath> = __ValidPath extends infer X ? Cast> : never; /** * Replaces invalid parts of a path with `never` * @param O to be inspected * @param Path to be validated * @returns [[Index]][] * @example * ```ts * import {A, L, O} from 'ts-toolbelt' * * // Get a property in an object `o` at any depth with `path` * // `A.Cast>` makes sure `path` is valid * const getAt = < * O extends object, * P extends L.List * >(o: O, path: A.Cast>): O.Path => { * let valueAt = o * * for (const p of path) * valueAt = valueAt[p] * * return valueAt as any * } * * const test0 = getAt({a: {b: {c: 1}}}, ['a', 'b'] as const) // {c: number} * const test1 = getAt({a: {b: {c: 1}}} as const, ['a', 'b'] as const) // {c: 1} * const test2 = getAt({a: {b: {c: 1}}}, ['x'] as const) // error * ``` */ export declare type ValidPath> = O extends unknown ? Path extends unknown ? _ValidPath : never : never; export {};