Skip to content

Instantly share code, notes, and snippets.

@Drag13
Created August 25, 2021 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Drag13/3c8947e71cf8595750d2cc236867d839 to your computer and use it in GitHub Desktop.
Save Drag13/3c8947e71cf8595750d2cc236867d839 to your computer and use it in GitHub Desktop.
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