types: fixed unreachable overloads (#6062)

This commit is contained in:
Antonio Román
2021-07-07 18:34:39 +02:00
committed by GitHub
parent 58bbcd591e
commit 7322547172
2 changed files with 77 additions and 15 deletions

23
typings/index.d.ts vendored
View File

@@ -2071,19 +2071,15 @@ export class ApplicationCommandManager<
null
>;
private commandPath({ id, guildId }: { id?: Snowflake; guildId?: Snowflake }): unknown;
public create(command: ApplicationCommandData): Promise<ApplicationCommandType>;
public create(command: ApplicationCommandData, guildId: Snowflake): Promise<ApplicationCommand>;
public create(command: ApplicationCommandData, guildId?: Snowflake): Promise<ApplicationCommandType>;
public delete(command: ApplicationCommandResolvable, guildId?: Snowflake): Promise<ApplicationCommandType | null>;
public edit(command: ApplicationCommandResolvable, data: ApplicationCommandData): Promise<ApplicationCommandType>;
public edit(
command: ApplicationCommandResolvable,
data: ApplicationCommandData,
guildId: Snowflake,
): Promise<ApplicationCommand>;
public edit(
command: ApplicationCommandResolvable,
data: ApplicationCommandData,
guildId?: Snowflake,
): Promise<ApplicationCommandType>;
public fetch(
id: Snowflake,
options: FetchApplicationCommandOptions & { guildId: Snowflake },
@@ -2093,14 +2089,11 @@ export class ApplicationCommandManager<
id?: Snowflake,
options?: FetchApplicationCommandOptions,
): Promise<Collection<Snowflake, ApplicationCommandType>>;
public set(commands: ApplicationCommandData[]): Promise<Collection<Snowflake, ApplicationCommandType>>;
public set(
commands: ApplicationCommandData[],
guildId?: Snowflake,
guildId: Snowflake,
): Promise<Collection<Snowflake, ApplicationCommand>>;
public set(
commands: ApplicationCommandData[],
guildId?: Snowflake,
): Promise<Collection<Snowflake, ApplicationCommandType>>;
private static transformCommand(command: ApplicationCommandData): unknown;
}
@@ -2163,7 +2156,7 @@ export class GuildApplicationCommandManager extends ApplicationCommandManager<Ap
public delete(command: ApplicationCommandResolvable): Promise<ApplicationCommand | null>;
public edit(command: ApplicationCommandResolvable, data: ApplicationCommandData): Promise<ApplicationCommand>;
public fetch(id: Snowflake, options?: BaseFetchOptions): Promise<ApplicationCommand>;
public fetch(id?: Snowflake, options?: BaseFetchOptions): Promise<Collection<Snowflake, ApplicationCommand>>;
public fetch(id?: undefined, options?: BaseFetchOptions): Promise<Collection<Snowflake, ApplicationCommand>>;
public set(commands: ApplicationCommandData[]): Promise<Collection<Snowflake, ApplicationCommand>>;
}
@@ -2190,7 +2183,7 @@ export class GuildChannelManager extends CachedManager<
options?: BaseFetchOptions,
): Promise<TextChannel | VoiceChannel | CategoryChannel | NewsChannel | StoreChannel | StageChannel | null>;
public fetch(
id?: Snowflake,
id?: undefined,
options?: BaseFetchOptions,
): Promise<
Collection<Snowflake, TextChannel | VoiceChannel | CategoryChannel | NewsChannel | StoreChannel | StageChannel>
@@ -2206,7 +2199,7 @@ export class GuildEmojiManager extends BaseGuildEmojiManager {
options?: GuildEmojiCreateOptions,
): Promise<GuildEmoji>;
public fetch(id: Snowflake, options?: BaseFetchOptions): Promise<GuildEmoji>;
public fetch(id?: Snowflake, options?: BaseFetchOptions): Promise<Collection<Snowflake, GuildEmoji>>;
public fetch(id?: undefined, options?: BaseFetchOptions): Promise<Collection<Snowflake, GuildEmoji>>;
}
export class GuildEmojiRoleManager extends DataManager<Snowflake, Role, RoleResolvable> {
@@ -2356,7 +2349,7 @@ export class RoleManager extends CachedManager<Snowflake, Role, RoleResolvable>
public readonly premiumSubscriberRole: Role | null;
public botRoleFor(user: UserResolvable): Role | null;
public fetch(id: Snowflake, options?: BaseFetchOptions): Promise<Role | null>;
public fetch(id?: Snowflake, options?: BaseFetchOptions): Promise<Collection<Snowflake, Role>>;
public fetch(id?: undefined, options?: BaseFetchOptions): Promise<Collection<Snowflake, Role>>;
public create(options?: CreateRoleOptions): Promise<Role>;
public edit(role: RoleResolvable, options: RoleData, reason?: string): Promise<Role>;
}

View File

@@ -1,9 +1,19 @@
import {
ApplicationCommand,
ApplicationCommandData,
ApplicationCommandManager,
ApplicationCommandResolvable,
CategoryChannel,
Client,
Collection,
Constants,
DMChannel,
GuildApplicationCommandManager,
GuildChannelManager,
GuildEmoji,
GuildEmojiManager,
GuildMember,
GuildResolvable,
Intents,
Message,
MessageActionRow,
@@ -17,13 +27,19 @@ import {
PartialTextBasedChannelFields,
Permissions,
ReactionCollector,
Role,
RoleManager,
Serialized,
ShardClientUtil,
ShardingManager,
Snowflake,
StageChannel,
StoreChannel,
TextBasedChannelFields,
TextChannel,
ThreadChannel,
User,
VoiceChannel,
} from '..';
const client: Client = new Client({
@@ -512,3 +528,56 @@ assertType<'close'>(Constants.ShardEvents.CLOSE);
assertType<1>(Constants.Status.CONNECTING);
assertType<0>(Constants.Opcodes.DISPATCH);
assertType<2>(Constants.ClientApplicationAssetTypes.BIG);
declare const applicationCommandData: ApplicationCommandData;
declare const applicationCommandResolvable: ApplicationCommandResolvable;
declare const applicationCommandManager: ApplicationCommandManager;
{
type ApplicationCommandType = ApplicationCommand<{ guild: GuildResolvable }>;
assertType<Promise<ApplicationCommandType>>(applicationCommandManager.create(applicationCommandData));
assertType<Promise<ApplicationCommand>>(applicationCommandManager.create(applicationCommandData, '0'));
assertType<Promise<ApplicationCommandType>>(
applicationCommandManager.edit(applicationCommandResolvable, applicationCommandData),
);
assertType<Promise<ApplicationCommand>>(
applicationCommandManager.edit(applicationCommandResolvable, applicationCommandData, '0'),
);
assertType<Promise<Collection<Snowflake, ApplicationCommandType>>>(
applicationCommandManager.set([applicationCommandData]),
);
assertType<Promise<Collection<Snowflake, ApplicationCommand>>>(
applicationCommandManager.set([applicationCommandData], '0'),
);
}
declare const guildApplicationCommandManager: GuildApplicationCommandManager;
assertType<Promise<Collection<Snowflake, ApplicationCommand>>>(guildApplicationCommandManager.fetch());
assertType<Promise<Collection<Snowflake, ApplicationCommand>>>(guildApplicationCommandManager.fetch(undefined, {}));
assertType<Promise<ApplicationCommand>>(guildApplicationCommandManager.fetch('0'));
declare const guildChannelManager: GuildChannelManager;
{
type AnyChannel = TextChannel | VoiceChannel | CategoryChannel | NewsChannel | StoreChannel | StageChannel;
assertType<Promise<VoiceChannel>>(guildChannelManager.create('name', { type: 'voice' }));
assertType<Promise<CategoryChannel>>(guildChannelManager.create('name', { type: 'category' }));
assertType<Promise<TextChannel>>(guildChannelManager.create('name', { type: 'text' }));
assertType<Promise<NewsChannel>>(guildChannelManager.create('name', { type: 'news' }));
assertType<Promise<StoreChannel>>(guildChannelManager.create('name', { type: 'store' }));
assertType<Promise<StageChannel>>(guildChannelManager.create('name', { type: 'stage' }));
assertType<Promise<Collection<Snowflake, AnyChannel>>>(guildChannelManager.fetch());
assertType<Promise<Collection<Snowflake, AnyChannel>>>(guildChannelManager.fetch(undefined, {}));
assertType<Promise<AnyChannel | null>>(guildChannelManager.fetch('0'));
}
declare const roleManager: RoleManager;
assertType<Promise<Collection<Snowflake, Role>>>(roleManager.fetch());
assertType<Promise<Collection<Snowflake, Role>>>(roleManager.fetch(undefined, {}));
assertType<Promise<Role | null>>(roleManager.fetch('0'));
declare const guildEmojiManager: GuildEmojiManager;
assertType<Promise<Collection<Snowflake, GuildEmoji>>>(guildEmojiManager.fetch());
assertType<Promise<Collection<Snowflake, GuildEmoji>>>(guildEmojiManager.fetch(undefined, {}));
assertType<Promise<GuildEmoji | null>>(guildEmojiManager.fetch('0'));