Declares a type-safe path to the nested property.
Notice: making path through optional properties is not possible.
Given a complex object structure:
interface Company { id: number; name: string; address: Address;}interface Address { country: string; region: string; street: Street; building: string;}interface Street { name: string; type: string;}
Use it to declare a type-safe tuple with a path to specific nested property:
const correctPath: DeepPath<Company> = ['address', 'street', 'name']; // okconst wrongPath: DeepPath<Company> = ['address', 'street', 'kind']; // compilation error
Use it to declare a generic type-safe path:
export function get<T, Path extends DeepPath<T>>(source: T, path: Path): DeepType<T, Path> { // ...}
Use the function:
const streetName = get(company, ['address', 'street', 'name']);const streetType = get(company, ['address', 'street', 'type']);const region = get(company, ['address', 'region']);
Type of the whole.
Generated using TypeDoc
Declares a type-safe path to the nested property.
Notice: making path through optional properties is not possible.
Example
Given a complex object structure:
Use it to declare a type-safe tuple with a path to specific nested property:
Use it to declare a generic type-safe path:
Use the function: