import { Path } from "./Path.js"; import { GetKey } from "./GetKey.js"; /** * Like Get returns the type of the value at a path of T. * However it does not require P to be a path of T, and will return undefined if not. * The advantage is less strain on the ts server, * in particular Get cannot handle infinitely nested objects but GET can. * * ``` * interface Doctor { * 9: { Actor: "Christopher" }; * 10: { Actor: "David" }; * 11: { Actor: "Matt" }; * 12: { Actor: "Peter" }; * 13: { Actor: "Jodie" }; * } * * type David = GET; // "David" * ``` */ type GET = P extends `${infer K}.${infer R}` ? GET, R> : GetKey; /** * Returns the type of the value at a path of T. * If the type is ambiguous returns a union. * If the object might not have the path, the union type will include undefined. * (This handles nullable graphql types) * * @typeParam T - The object type * @typeParam P - The dot-notation path string * * @example * ``` * interface Doctor { * 9: { Actor: "Christopher" }; * 10: { Actor: "David" }; * 11: { Actor: "Matt" }; * 12: { Actor: "Peter" }; * 13: { Actor: "Jodie" }; * } * * type David = Get; // "David" * ``` * * @example * ``` * type Obj = { user: { name: string } }; * type Name = Get; // string * ``` */ type Get> = GET; /** * * @param obj object to access * @param path path to access in the object (e.g. `"a.b.c"`) * @returns value at the path `Get` * ``` * const doctor = { * 9: { Actor: "Christopher" }, * 10: { Actor: "David" }, * 11: { Actor: "Matt" }, * 12: { Actor: "Peter" }, * 13: { Actor: "Jodie" }, * } as const; * * const david = get(doctor, "10.Actor"); // "David" * ``` */ declare function get>(obj: T, path: P): Get; export { Get, GET, get }; //# sourceMappingURL=Get.d.ts.map