fix: optionalize recursive type works with nested objects and arrays (#2115)

* fix: get rid of type errors for now

* fix: only 6 type errors left
This commit is contained in:
Yuzu
2022-03-19 09:12:37 +00:00
committed by GitHub
parent cf13780765
commit 81678fbc22
2 changed files with 13 additions and 12 deletions

View File

@@ -67,7 +67,6 @@ export function setupCacheRemovals<B extends Bot>(bot: BotWithCache<B>) {
bot.handlers.GUILD_EMOJIS_UPDATE = function (_, data, shardId) {
const payload = data.d as DiscordGuildEmojisUpdate;
const guild = bot.guilds.get(bot.transformers.snowflake(payload.guild_id));
if (guild) {

View File

@@ -1242,7 +1242,7 @@ export type Camelize<T> = {
: never;
};
// export type Optionalize<T> = T extends object ?
// export type Optionalize<T> = T extends object ?
// & {
// [K in KeysWithUndefined<T>]?: Optionalize<T[K]>;
// }
@@ -1252,17 +1252,19 @@ export type Camelize<T> = {
// : T;
export type KeysWithUndefined<T> = {
[K in keyof T]-?: (undefined | null) extends T[K] ? K : never;
[K in keyof T]-?: undefined extends T[K]
? K
: null extends T[K]
? K
: never;
}[keyof T];
export type Optionalize<T> = (
& {
[K in KeysWithUndefined<T>]?: Optionalize<T[K]>;
&{
[K in KeysWithUndefined<T>]?: T[K]
} & {
[K in Exclude<keyof T, KeysWithUndefined<T>>]: T[K] extends object
? Object extends Pick<T[K], keyof T[K]> ? T[K] : Optionalize<T[K]>
: T[K];
}
& {
[K in Exclude<keyof T, KeysWithUndefined<T>>]: (
// deno-lint-ignore ban-types
T[K] extends object ? Object extends Pick<T[K], keyof T[K]> ? T[K] : Optionalize<T[K]> : T[K]
);
}
);
);