Type alias TransferPath<P, Path>

TransferPath<P, Path>: P extends ""
    ? P
    : Path extends `[${infer K}]${infer NextK}`
        ? `${K}${EmptyNotDef<NextK, `.${TransferPath<NextK>}`>}`
        : Path extends `${infer K}[${infer NextK}]${infer Other}`
            ? `${DotTrim<K>}${EmptyNotDef<NextK, `.${NextK}`>}${EmptyNotDef<BracketsToEmpty<Other>, `.${TransferPath<Other>}`>}`
            : Path extends `${infer K}.${infer NextK}`
                ? `${K}.${TransferPath<NextK>}`
                : Path

路径类型转换

Type Parameters

Example

type T1 = TransferPath<'[a]'>;         // a
type T2 = TransferPath<'[a][b][c]'>; // a.b.c
type T3 = TransferPath<'a.b.c'>; // a.b.c
type T4 = TransferPath<'a[b]'>; // a.b
type T5 = TransferPath<'a.[b]'>; // a.b
type T6 = TransferPath<'[a][b][c'>; // error a.b.[c
type T7 = TransferPath<'a[b][c]'>; // a.b.c
type T8 = TransferPath<'a[b]c'>; // a.b.c
type T9 = TransferPath<'a[b].c'>; // a.b.c
type T10 = TransferPath<'[a][b]c'>; // a.b.c