Skip to content

Commit

Permalink
types(GuildChannelManager): correct fetch return type (#8549)
Browse files Browse the repository at this point in the history
* types(GuildChannelManager): correct `fetch` return type

* fix(ci): fix the types tests

* fix: fix the docs

* Update packages/discord.js/src/managers/GuildChannelManager.js

Co-authored-by: Almeida <almeidx@pm.me>

* types: allow channels in the collection to be null

Signed-off-by: RedGuy12 <61329810+RedGuy12@users.noreply.github.com>

* style: run prettier

Signed-off-by: RedGuy12 <61329810+RedGuy12@users.noreply.github.com>

* test: fix types again

Signed-off-by: RedGuy12 <61329810+RedGuy12@users.noreply.github.com>

* style: run prettier

Signed-off-by: RedGuy12 <61329810+RedGuy12@users.noreply.github.com>

Signed-off-by: RedGuy12 <61329810+RedGuy12@users.noreply.github.com>
Co-authored-by: Almeida <almeidx@pm.me>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Sep 11, 2022
1 parent 8e1afae commit 1d4cdee
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/discord.js/src/managers/GuildChannelManager.js
Expand Up @@ -317,7 +317,7 @@ class GuildChannelManager extends CachedManager {
* Obtains one or more guild channels from Discord, or the channel cache if they're already available.
* @param {Snowflake} [id] The channel's id
* @param {BaseFetchOptions} [options] Additional options for this fetch
* @returns {Promise<?GuildChannel|Collection<Snowflake, GuildChannel>>}
* @returns {Promise<?GuildChannel|ThreadChannel|Collection<Snowflake, ?GuildChannel>>}
* @example
* // Fetch all channels from the guild (excluding threads)
* message.guild.channels.fetch()
Expand Down
7 changes: 5 additions & 2 deletions packages/discord.js/typings/index.d.ts
Expand Up @@ -3364,8 +3364,11 @@ export class GuildChannelManager extends CachedManager<Snowflake, GuildBasedChan
public create(options: GuildChannelCreateOptions): Promise<TextChannel>;
public createWebhook(options: WebhookCreateOptions): Promise<Webhook>;
public edit(channel: GuildChannelResolvable, data: GuildChannelEditOptions): Promise<GuildChannel>;
public fetch(id: Snowflake, options?: BaseFetchOptions): Promise<NonThreadGuildBasedChannel | null>;
public fetch(id?: undefined, options?: BaseFetchOptions): Promise<Collection<Snowflake, NonThreadGuildBasedChannel>>;
public fetch(id: Snowflake, options?: BaseFetchOptions): Promise<GuildBasedChannel | null>;
public fetch(
id?: undefined,
options?: BaseFetchOptions,
): Promise<Collection<Snowflake, NonThreadGuildBasedChannel | null>>;
public fetchWebhooks(channel: GuildChannelResolvable): Promise<Collection<Snowflake, Webhook>>;
public setPosition(
channel: GuildChannelResolvable,
Expand Down
6 changes: 3 additions & 3 deletions packages/discord.js/typings/index.test-d.ts
Expand Up @@ -1187,9 +1187,9 @@ declare const guildChannelManager: GuildChannelManager;
expectType<Promise<NewsChannel>>(guildChannelManager.create({ name: 'name', type: ChannelType.GuildNews }));
expectType<Promise<StageChannel>>(guildChannelManager.create({ name: 'name', type: ChannelType.GuildStageVoice }));

expectType<Promise<Collection<Snowflake, AnyChannel>>>(guildChannelManager.fetch());
expectType<Promise<Collection<Snowflake, AnyChannel>>>(guildChannelManager.fetch(undefined, {}));
expectType<Promise<AnyChannel | null>>(guildChannelManager.fetch('0'));
expectType<Promise<Collection<Snowflake, AnyChannel | null>>>(guildChannelManager.fetch());
expectType<Promise<Collection<Snowflake, AnyChannel | null>>>(guildChannelManager.fetch(undefined, {}));
expectType<Promise<GuildBasedChannel | null>>(guildChannelManager.fetch('0'));

const channel = guildChannelManager.cache.first()!;

Expand Down

0 comments on commit 1d4cdee

Please sign in to comment.