//#region src/get-field.d.ts /** * See the definition of `@types/lodash`. */ type GetIndexedField = K extends keyof T ? T[K] : K extends `${number}` ? "length" extends keyof T ? number extends T["length"] ? number extends keyof T ? T[number] : undefined : undefined : undefined : undefined; type FieldWithPossiblyUndefined = GetField, Key> | Extract; type IndexedFieldWithPossiblyUndefined = GetIndexedField, Key> | Extract; type GetField = P extends `${infer Left}.${infer Right}` ? Left extends keyof Exclude ? FieldWithPossiblyUndefined[Left], Right> | Extract : Left extends `${infer FieldKey}[${infer IndexKey}]` ? FieldKey extends keyof T ? FieldWithPossiblyUndefined, Right> : undefined : undefined : P extends keyof T ? T[P] : P extends `${infer FieldKey}[${infer IndexKey}]` ? FieldKey extends keyof T ? IndexedFieldWithPossiblyUndefined : undefined : IndexedFieldWithPossiblyUndefined; /** * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead. * * @typeParam T - The type of the object. * @typeParam K - The type of the key in the object. * * @param object - The object to query. * @param path - The path of the property to get. * @returns The resolved value. */ declare function getField(object: T, path: K | readonly [K]): T[K]; /** * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead. * * @typeParam T - The type of the object. * @typeParam K - The type of the key in the object. * * @param object - The object to query. * @param path - The path of the property to get. * @returns The resolved value or undefined. */ declare function getField(object: T | null | undefined, path: K | readonly [K]): T[K] | undefined; /** * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead. * * @typeParam T - The type of the object. * @typeParam K - The type of the key in the object. * @typeParam D - The type of the default value. * * @param object - The object to query. * @param path - The path of the property to get. * @param defaultValue - The value returned if the resolved value is undefined. * @returns The resolved value or default value. */ declare function getField(object: T | null | undefined, path: K | readonly [K], defaultValue: D): Exclude | D; /** * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead. * * @typeParam T - The type of the object. * @typeParam K1 - The type of the first key in the object. * @typeParam K2 - The type of the second key in the object. * * @param object - The object to query. * @param path - The path of the property to get. * @returns The resolved value. */ declare function getField(object: T, path: readonly [K1, K2]): T[K1][K2]; /** * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead. * * @typeParam T - The type of the object. * @typeParam K1 - The type of the first key in the object. * @typeParam K2 - The type of the second key in the object. * * @param object - The object to query. * @param path - The path of the property to get. * @returns The resolved value or undefined. */ declare function getField(object: T | null | undefined, path: readonly [K1, K2]): T[K1][K2] | undefined; /** * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead. * * @typeParam T - The type of the object. * @typeParam K1 - The type of the first key in the object. * @typeParam K2 - The type of the second key in the object. * @typeParam D - The type of the default value. * * @param object - The object to query. * @param path - The path of the property to get. * @param defaultValue - The value returned if the resolved value is undefined. * @returns The resolved value or default value. */ declare function getField(object: T | null | undefined, path: readonly [K1, K2], defaultValue: D): Exclude | D; /** * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead. * * @typeParam T - The type of the object. * @typeParam K1 - The type of the first key in the object. * @typeParam K2 - The type of the second key in the object. * @typeParam K3 - The type of the third key in the object. * * @param object - The object to query. * @param path - The path of the property to get. * @returns The resolved value. */ declare function getField(object: T, path: readonly [K1, K2, K3]): T[K1][K2][K3]; /** * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead. * * @typeParam T - The type of the object. * @typeParam K1 - The type of the first key in the object. * @typeParam K2 - The type of the second key in the object. * @typeParam K3 - The type of the third key in the object. * * @param object - The object to query. * @param path - The path of the property to get. * @returns The resolved value or undefined. */ declare function getField(object: T | null | undefined, path: readonly [K1, K2, K3]): T[K1][K2][K3] | undefined; /** * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead. * * @typeParam T - The type of the object. * @typeParam K1 - The type of the first key in the object. * @typeParam K2 - The type of the second key in the object. * @typeParam K3 - The type of the third key in the object. * @typeParam D - The type of the default value. * * @param object - The object to query. * @param path - The path of the property to get. * @param defaultValue - The value returned if the resolved value is undefined. * @returns The resolved value or default value. */ declare function getField(object: T | null | undefined, path: readonly [K1, K2, K3], defaultValue: D): Exclude | D; /** * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead. * * @typeParam T - The type of the object. * @typeParam K1 - The type of the first key in the object. * @typeParam K2 - The type of the second key in the object. * @typeParam K3 - The type of the third key in the object. * @typeParam K4 - The type of the fourth key in the object. * * @param object - The object to query. * @param path - The path of the property to get. * @returns The resolved value. */ declare function getField(object: T, path: readonly [K1, K2, K3, K4]): T[K1][K2][K3][K4]; /** * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead. * * @typeParam T - The type of the object. * @typeParam K1 - The type of the first key in the object. * @typeParam K2 - The type of the second key in the object. * @typeParam K3 - The type of the third key in the object. * @typeParam K4 - The type of the fourth key in the object. * * @param object - The object to query. * @param path - The path of the property to get. * @returns The resolved value or undefined. */ declare function getField(object: T | null | undefined, path: readonly [K1, K2, K3, K4]): T[K1][K2][K3][K4] | undefined; /** * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead. * * @typeParam T - The type of the object. * @typeParam K1 - The type of the first key in the object. * @typeParam K2 - The type of the second key in the object. * @typeParam K3 - The type of the third key in the object. * @typeParam K4 - The type of the fourth key in the object. * @typeParam D - The type of the default value. * * @param object - The object to query. * @param path - The path of the property to get. * @param defaultValue - The value returned if the resolved value is undefined. * @returns The resolved value or default value. */ declare function getField(object: T | null | undefined, path: readonly [K1, K2, K3, K4], defaultValue: D): Exclude | D; /** * Retrieves the value at a given path from an object with numeric keys. If the resolved value is undefined, the defaultValue is returned instead. * * @typeParam T - The type of the value. * * @param object - The object to query. * @param path - The path of the property to get. * @returns The resolved value. */ declare function getField(object: Record, path: number): T; /** * Retrieves the value at a given path from an object with numeric keys. If the resolved value is undefined, the defaultValue is returned instead. * * @typeParam T - The type of the value. * * @param object - The object to query. * @param path - The path of the property to get. * @returns The resolved value or undefined. */ declare function getField(object: Record | null | undefined, path: number): T | undefined; /** * Retrieves the value at a given path from an object with numeric keys. If the resolved value is undefined, the defaultValue is returned instead. * * @typeParam T - The type of the value. * @typeParam D - The type of the default value. * * @param object - The object to query. * @param path - The path of the property to get. * @param defaultValue - The value returned if the resolved value is undefined. * @returns The resolved value or default value. */ declare function getField(object: Record | null | undefined, path: number, defaultValue: D): T | D; /** * Retrieves the value at a given path from a null or undefined object, returning the default value. * * @typeParam D - The type of the default value. * * @param object - The object to query. * @param path - The path of the property to get. * @param defaultValue - The value returned if the resolved value is undefined. * @returns The default value. */ declare function getField(object: null | undefined, path: PropertyKey, defaultValue: D): D; /** * Retrieves the value at a given path from a null or undefined object, returning undefined. * * @param object - The object to query. * @param path - The path of the property to get. */ declare function getField(object: null | undefined, path: PropertyKey): undefined; /** * Retrieves the value at a given path from a string-keyed object. If the resolved value is undefined, the defaultValue is returned instead. * * @typeParam T - The type of the object. * @typeParam P - The type of the path. * * @param data - The object to query. * @param path - The path of the property to get. * @returns The resolved value, or any if path is a general string. */ declare function getField(data: T, path: P): string extends P ? any : GetField; /** * Retrieves the value at a given path from a string-keyed object. If the resolved value is undefined, the defaultValue is returned instead. * * @typeParam T - The type of the object. * @typeParam P - The type of the path. * @typeParam D - The type of the default value. * * @param data - The object to query. * @param path - The path of the property to get. * @param defaultValue - The value returned if the resolved value is undefined. * @returns The resolved value or default value. */ declare function getField>(data: T, path: P, defaultValue: D): Exclude, null | undefined> | D; /** * Retrieves the value at a given path from an object. If the resolved value is undefined, the defaultValue is returned instead. * * @param object - The object to query. * @param path - The path of the property to get. * @param defaultValue - The value returned if the resolved value is undefined. * @returns The resolved value. */ declare function getField(object: unknown, path: PropertyKey | readonly PropertyKey[], defaultValue?: unknown): any; //#endregion export { GetField, getField }; //# sourceMappingURL=get-field.d.mts.map