Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
8 lines
981 B
Plaintext
8 lines
981 B
Plaintext
import { Prettify } from "../prettify";
|
|
type ExtractFromObject<Obj extends Record<PropertyKey, unknown>, Key> = Key extends keyof Obj ? Obj[Key] : Key extends keyof NonNullable<Obj> ? NonNullable<Obj>[Key] | undefined : undefined;
|
|
type ExtractFromArray<Arr extends readonly any[], Key> = any[] extends Arr ? Arr extends readonly (infer T)[] ? T | undefined : undefined : Key extends keyof Arr ? Arr[Key] : undefined;
|
|
type GetWithArray<Type, Path, PrettifiedType = Prettify<Type>> = Path extends [] ? Type : Path extends [infer Key, ...infer Rest] ? PrettifiedType extends Record<PropertyKey, unknown> ? GetWithArray<ExtractFromObject<PrettifiedType, Key>, Rest> : Type extends readonly any[] ? GetWithArray<ExtractFromArray<Type, Key>, Rest> : undefined : never;
|
|
type Path<Type> = Type extends `${infer Key}.${infer Rest}` ? [Key, ...Path<Rest>] : Type extends `${infer Key}` ? [Key] : [];
|
|
export type PathValue<Type, StringPath> = GetWithArray<Type, Path<StringPath>>;
|
|
export {};
|