diff --git a/deno/rest/v10/guild.ts b/deno/rest/v10/guild.ts index 9b371db1..51dd4b83 100644 --- a/deno/rest/v10/guild.ts +++ b/deno/rest/v10/guild.ts @@ -26,10 +26,11 @@ import type { } from '../../payloads/v10/mod.ts'; import type { AddUndefinedToPossiblyUndefinedPropertiesOfInterface, + DistributiveOmit, + DistributivePick, Nullable, StrictPartial, StrictRequired, - UnionToIntersection, } from '../../utils/internals.ts'; export interface APIGuildCreateOverwrite extends RESTPutAPIChannelPermissionJSONBody { @@ -38,9 +39,9 @@ export interface APIGuildCreateOverwrite extends RESTPutAPIChannelPermissionJSON export type APIGuildChannelResolvable = Exclude; export type APIGuildCreatePartialChannel = StrictPartial< - Pick< - UnionToIntersection, - 'type' | 'topic' | 'nsfw' | 'bitrate' | 'user_limit' | 'rate_limit_per_user' + DistributivePick< + APIGuildChannelResolvable, + 'type' | 'topic' | 'nsfw' | 'bitrate' | 'user_limit' | 'rate_limit_per_user' | 'default_auto_archive_duration' > > & AddUndefinedToPossiblyUndefinedPropertiesOfInterface<{ @@ -291,7 +292,7 @@ export type RESTGetAPIGuildChannelsResult = APIChannel[]; /** * https://discord.com/developers/docs/resources/guild#create-guild-channel */ -export type RESTPostAPIGuildChannelJSONBody = Omit; +export type RESTPostAPIGuildChannelJSONBody = DistributiveOmit; /** * https://discord.com/developers/docs/resources/guild#create-guild-channel diff --git a/deno/rest/v9/guild.ts b/deno/rest/v9/guild.ts index fa7ed206..90ffbffa 100644 --- a/deno/rest/v9/guild.ts +++ b/deno/rest/v9/guild.ts @@ -26,10 +26,11 @@ import type { } from '../../payloads/v9/mod.ts'; import type { AddUndefinedToPossiblyUndefinedPropertiesOfInterface, + DistributiveOmit, + DistributivePick, Nullable, StrictPartial, StrictRequired, - UnionToIntersection, } from '../../utils/internals.ts'; export interface APIGuildCreateOverwrite extends RESTPutAPIChannelPermissionJSONBody { @@ -38,9 +39,9 @@ export interface APIGuildCreateOverwrite extends RESTPutAPIChannelPermissionJSON export type APIGuildChannelResolvable = Exclude; export type APIGuildCreatePartialChannel = StrictPartial< - Pick< - UnionToIntersection, - 'type' | 'topic' | 'nsfw' | 'bitrate' | 'user_limit' | 'rate_limit_per_user' + DistributivePick< + APIGuildChannelResolvable, + 'type' | 'topic' | 'nsfw' | 'bitrate' | 'user_limit' | 'rate_limit_per_user' | 'default_auto_archive_duration' > > & AddUndefinedToPossiblyUndefinedPropertiesOfInterface<{ @@ -291,7 +292,7 @@ export type RESTGetAPIGuildChannelsResult = APIChannel[]; /** * https://discord.com/developers/docs/resources/guild#create-guild-channel */ -export type RESTPostAPIGuildChannelJSONBody = Omit; +export type RESTPostAPIGuildChannelJSONBody = DistributiveOmit; /** * https://discord.com/developers/docs/resources/guild#create-guild-channel diff --git a/deno/utils/internals.ts b/deno/utils/internals.ts index fea21fab..21510966 100644 --- a/deno/utils/internals.ts +++ b/deno/utils/internals.ts @@ -14,4 +14,26 @@ export type StrictPartial = AddUndefinedToPossiblyUndefinedPropertiesOfInt export type StrictRequired = Required<{ [K in keyof Base]: Exclude }>; -export type UnionToIntersection = (T extends any ? (x: T) => any : never) extends (x: infer R) => any ? R : never; +export type UnionToIntersection = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never; + +type Keys = keyof T; +type DistributiveKeys = T extends unknown ? Keys : never; +/** + * Allows picking of keys from unions that are disjoint + */ +export type DistributivePick> = T extends unknown + ? keyof Pick_ extends never + ? never + : { [P in keyof Pick_]: Pick_[P] } + : never; + +type Pick_ = Pick>; + +/** + * Allows omitting of keys from unions that are disjoint + */ +export type DistributiveOmit> = T extends unknown + ? { [P in keyof Omit_]: Omit_[P] } + : never; + +type Omit_ = Omit>; diff --git a/rest/v10/guild.ts b/rest/v10/guild.ts index 7b819621..c65d61a0 100644 --- a/rest/v10/guild.ts +++ b/rest/v10/guild.ts @@ -26,10 +26,11 @@ import type { } from '../../payloads/v10/index'; import type { AddUndefinedToPossiblyUndefinedPropertiesOfInterface, + DistributiveOmit, + DistributivePick, Nullable, StrictPartial, StrictRequired, - UnionToIntersection, } from '../../utils/internals'; export interface APIGuildCreateOverwrite extends RESTPutAPIChannelPermissionJSONBody { @@ -38,9 +39,9 @@ export interface APIGuildCreateOverwrite extends RESTPutAPIChannelPermissionJSON export type APIGuildChannelResolvable = Exclude; export type APIGuildCreatePartialChannel = StrictPartial< - Pick< - UnionToIntersection, - 'type' | 'topic' | 'nsfw' | 'bitrate' | 'user_limit' | 'rate_limit_per_user' + DistributivePick< + APIGuildChannelResolvable, + 'type' | 'topic' | 'nsfw' | 'bitrate' | 'user_limit' | 'rate_limit_per_user' | 'default_auto_archive_duration' > > & AddUndefinedToPossiblyUndefinedPropertiesOfInterface<{ @@ -291,7 +292,7 @@ export type RESTGetAPIGuildChannelsResult = APIChannel[]; /** * https://discord.com/developers/docs/resources/guild#create-guild-channel */ -export type RESTPostAPIGuildChannelJSONBody = Omit; +export type RESTPostAPIGuildChannelJSONBody = DistributiveOmit; /** * https://discord.com/developers/docs/resources/guild#create-guild-channel diff --git a/rest/v9/guild.ts b/rest/v9/guild.ts index 956c3d7c..6fea821f 100644 --- a/rest/v9/guild.ts +++ b/rest/v9/guild.ts @@ -26,10 +26,11 @@ import type { } from '../../payloads/v9/index'; import type { AddUndefinedToPossiblyUndefinedPropertiesOfInterface, + DistributiveOmit, + DistributivePick, Nullable, StrictPartial, StrictRequired, - UnionToIntersection, } from '../../utils/internals'; export interface APIGuildCreateOverwrite extends RESTPutAPIChannelPermissionJSONBody { @@ -38,9 +39,9 @@ export interface APIGuildCreateOverwrite extends RESTPutAPIChannelPermissionJSON export type APIGuildChannelResolvable = Exclude; export type APIGuildCreatePartialChannel = StrictPartial< - Pick< - UnionToIntersection, - 'type' | 'topic' | 'nsfw' | 'bitrate' | 'user_limit' | 'rate_limit_per_user' + DistributivePick< + APIGuildChannelResolvable, + 'type' | 'topic' | 'nsfw' | 'bitrate' | 'user_limit' | 'rate_limit_per_user' | 'default_auto_archive_duration' > > & AddUndefinedToPossiblyUndefinedPropertiesOfInterface<{ @@ -291,7 +292,7 @@ export type RESTGetAPIGuildChannelsResult = APIChannel[]; /** * https://discord.com/developers/docs/resources/guild#create-guild-channel */ -export type RESTPostAPIGuildChannelJSONBody = Omit; +export type RESTPostAPIGuildChannelJSONBody = DistributiveOmit; /** * https://discord.com/developers/docs/resources/guild#create-guild-channel diff --git a/utils/internals.ts b/utils/internals.ts index fea21fab..21510966 100644 --- a/utils/internals.ts +++ b/utils/internals.ts @@ -14,4 +14,26 @@ export type StrictPartial = AddUndefinedToPossiblyUndefinedPropertiesOfInt export type StrictRequired = Required<{ [K in keyof Base]: Exclude }>; -export type UnionToIntersection = (T extends any ? (x: T) => any : never) extends (x: infer R) => any ? R : never; +export type UnionToIntersection = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never; + +type Keys = keyof T; +type DistributiveKeys = T extends unknown ? Keys : never; +/** + * Allows picking of keys from unions that are disjoint + */ +export type DistributivePick> = T extends unknown + ? keyof Pick_ extends never + ? never + : { [P in keyof Pick_]: Pick_[P] } + : never; + +type Pick_ = Pick>; + +/** + * Allows omitting of keys from unions that are disjoint + */ +export type DistributiveOmit> = T extends unknown + ? { [P in keyof Omit_]: Omit_[P] } + : never; + +type Omit_ = Omit>;