Created
September 22, 2021 21:45
-
-
Save flisboac/e568ada339bc287b124197bceaedb273 to your computer and use it in GitHub Desktop.
static-convert-path.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ToPathIndexArray<S extends string> = | |
S extends `${infer N}[${infer P}]` ? [N, P] : [S]; | |
type ToPathArray<P extends string, _R extends string[] = []> = | |
P extends `${infer NS}.${infer N}` | |
? NS extends `${infer IN}[${infer I}]` | |
? [IN, I, ...ToPathArray<N>, ..._R] | |
: [...ToPathIndexArray<NS>, ...ToPathArray<N>, ..._R] | |
: P extends `${infer IN}[${infer I}]` | |
? [IN, I, ..._R] | |
: P extends '[' | |
? never | |
: [P, ..._R] | |
type T3 = ToPathIndexArray<'a'> | |
type T2 = ToPathArray<'a[1].x.b[1]'> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment