@flex-development/tutils
Version:
TypeScript utilities
31 lines (27 loc) • 719 B
text/typescript
/**
* @file Type Definitions - PathValue
* @module tutils/types/PathValue
*/
import type ObjectPlain from './object-plain'
import type Path from './path'
/**
* Constructs a type representing a property value of `T`.
*
* @see https://github.com/ghoullier/awesome-template-literal-types#dot-notation-string-type-safe
*
* @template T - Object type
* @template P - Object path (dot notation friendly)
*/
type PathValue<
T extends ObjectPlain,
P extends Path<T> = Path<T>
> = P extends `${infer Key}.${infer Rest}`
? Key extends keyof T
? Rest extends Path<T[Key]>
? PathValue<T[Key], Rest>
: never
: never
: P extends keyof T
? T[P]
: never
export { type PathValue as default }