@omnia/fx
Version:
Provide Omnia Fx typings and tooling for clientside Omnia development.
15 lines (14 loc) • 843 B
TypeScript
import { PropPathCheckTargetType } from "./propertyPath";
export type PropPathType<T, Path extends string> = string extends Path ? never : Path extends keyof T ? T[Path] : Path extends `${infer K}.${infer R}` ? K extends keyof T ? PropPathType<T[K], R> : never : never;
/**
* Get a value from a property path and preserv type of the target on that path
*
* Example:
* let test:string = propertyPathValue(instance,'Prop1.Prop2'); //will only work if type is also string for the path
* let test2 = propertyPathValue(instance,'Prop1.Prop2'); //test2 will have the same type as Prop2
*
*
* @param obj The object to get value from by path
* @param path The object property path to get
*/
export declare const propertyPathValue: <T, P extends string>(obj: T, path: PropPathCheckTargetType<T, P, PropPathType<T, P>>) => PropPathType<T, P>;