getDataProp()function
getDataProp(data: T, path: K): BranchData<T>[K]
getDataProp(data: DeepPartial<T>, path: K): BranchData<T>[K] | undefined
getDataProp(data: Data, path: string | Segments): unknown
| Param | Type | |
|---|---|---|
data | T | The data object to read from. required |
path | K | The dotted path string (e.g. "a.b") or an array of segments pointing at the prop. required |
data | DeepPartial<T> | Deep partial object: deeply convert an object to its partial version. required |
path | K | required |
data | Data | Data object — a plain object with string keys and unknown values. required |
path | stringSegments | required |
| Return | |
|---|---|
BranchData<T>[K] | The value at the path, or undefined if any segment along the path doesn't exist. |
BranchData<T>[K] | undefined | |
unknown |
Get an optional (possibly deep) prop from a data object, or undefined if it doesn't exist.
Examples
getDataProp<{ a: { b: number } }>({ a: { b: 123 } }, ["a", "b"]); // 123getDataProp<{ a: { b: number } }>({ a: { b: 123 } }, "a.b"); // 123getDataProp({ a: { b: 123 } } as Data, "x.y.z"); // undefined