mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-03 17:30:07 +00:00
fix: optionalize handle arrays better. Thx yui
This commit is contained in:
@@ -1311,16 +1311,23 @@ export type KeysWithUndefined<T> = {
|
||||
: never;
|
||||
}[keyof T];
|
||||
|
||||
export type Optionalize<T> = T extends Collection<any, any> ? T : T extends object ? Id<
|
||||
& {
|
||||
[K in KeysWithUndefined<T>]?: T[K] extends Collection<any, any> ? T[K] : Optionalize<T[K]>;
|
||||
}
|
||||
& {
|
||||
[K in Exclude<keyof T, KeysWithUndefined<T>>]: T[K] extends object ? {} extends Pick<T[K], keyof T[K]> ? T[K]
|
||||
: T[K] extends Collection<any, any> ? T[K]
|
||||
: T[K] extends unknown[] ? T[K]
|
||||
: Optionalize<T[K]>
|
||||
: T[K];
|
||||
}
|
||||
>
|
||||
: T;
|
||||
export type Optionalize<T> =
|
||||
// Collections don't need optionalizing
|
||||
T extends Collection<any, any> ? T
|
||||
// If an array only optionalize objects in arrays
|
||||
: T extends unknown[] ? T[number] extends Record<any, any> ? Array<Optionalize<T[number]>>
|
||||
: T
|
||||
// Specific optionalizing of {} go here
|
||||
: T extends object ? Id<
|
||||
& {
|
||||
[K in KeysWithUndefined<T>]?: T[K] extends Collection<any, any> ? T[K] : Optionalize<T[K]>;
|
||||
}
|
||||
& {
|
||||
[K in Exclude<keyof T, KeysWithUndefined<T>>]: T[K] extends object ? {} extends Pick<T[K], keyof T[K]> ? T[K]
|
||||
: T[K] extends Collection<any, any> ? T[K]
|
||||
: T[K] extends unknown[] ? T[K]
|
||||
: Optionalize<T[K]>
|
||||
: T[K];
|
||||
}
|
||||
>
|
||||
: T;
|
||||
|
||||
Reference in New Issue
Block a user