Created
August 25, 2021 17:28
-
-
Save Drag13/3c8947e71cf8595750d2cc236867d839 to your computer and use it in GitHub Desktop.
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 User = { name: string }; | |
type MyModel = { | |
name: string; | |
users: User[]; | |
} | |
type OnlyArrays<TModel> = Exclude<{ [key in keyof TModel]?: TModel[key] extends any[] ? key : never }[keyof TModel], undefined>; | |
type Numbers = '0' | '1' | '2' | '3' | '4' | '5'; | |
type StringKeyof<TModel> = keyof TModel extends string ? keyof TModel : never; | |
type Keys<TModel extends { [key: string]: any }, TProp extends string> = `${TProp}.${Numbers}.${StringKeyof<TModel>}`; | |
type Mapped<TValue> = Partial<{ [key in Keys<User, OnlyArrays<MyModel>>]: TValue }>; | |
const test: Mapped<string> = { | |
"users.0.name": 'test', | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment