You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
706 B
TypeScript
30 lines
706 B
TypeScript
type Join<K, P> = K extends string | number
|
|
? P extends string | number
|
|
? `${K}.${P}`
|
|
: never
|
|
: never;
|
|
|
|
type Paths<T> = T extends object
|
|
? {
|
|
[K in keyof T]-?: K extends string | number
|
|
? T[K] extends object
|
|
? `${K}` | Join<K, Paths<T[K]>>
|
|
: `${K}`
|
|
: never;
|
|
}[keyof T]
|
|
: never;
|
|
|
|
export type ValidationErrorsObj<T extends Record<string, unknown>> = Partial<{
|
|
[K in keyof T]: ValidationErrors<T[K]>;
|
|
}>;
|
|
|
|
export type ValidationErrorsArray<T extends unknown[]> = Partial<{
|
|
[K in keyof T]: ValidationErrors<T[K]>;
|
|
}>;
|
|
|
|
export type ValidationErrors<T> = T extends Record<string, unknown>
|
|
? ValidationErrorsObj<T>
|
|
: T extends unknown[]
|
|
? ValidationErrorsArray<T>
|
|
: string[];
|