Skip to content

Commit 4bc1dae

Browse files
types: use wrapper utilities (#9945)
* types: use `Awaitable<T>` instead of `Promise<T> | T` * types: use `JSONEncodable<T>` over raw definition --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent cc07a28 commit 4bc1dae

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

packages/discord.js/typings/index.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,7 @@ export abstract class Collector<Key, Value, Extras extends unknown[] = []> exten
11291129
public toJSON(): unknown;
11301130

11311131
protected listener: (...args: any[]) => void;
1132-
public abstract collect(...args: unknown[]): Key | null | Promise<Key | null>;
1132+
public abstract collect(...args: unknown[]): Awaitable<Key | null>;
11331133
public abstract dispose(...args: unknown[]): Key | null;
11341134

11351135
public on<EventKey extends keyof CollectorEventTypes<Key, Value, Extras>>(
@@ -5066,7 +5066,7 @@ export interface CloseEvent {
50665066
reason: string;
50675067
}
50685068

5069-
export type CollectorFilter<Arguments extends unknown[]> = (...args: Arguments) => boolean | Promise<boolean>;
5069+
export type CollectorFilter<Arguments extends unknown[]> = (...args: Arguments) => Awaitable<boolean>;
50705070

50715071
export interface CollectorOptions<FilterArguments extends unknown[]> {
50725072
filter?: CollectorFilter<FilterArguments>;
@@ -6647,7 +6647,7 @@ export type Serialized<Value> = Value extends symbol | bigint | (() => any)
66476647
? never
66486648
: Value extends number | string | boolean | undefined
66496649
? Value
6650-
: Value extends { toJSON(): infer JSONResult }
6650+
: Value extends JSONEncodable<infer JSONResult>
66516651
? JSONResult
66526652
: Value extends ReadonlyArray<infer ItemType>
66536653
? Serialized<ItemType>[]

packages/discord.js/typings/index.test-d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ import {
185185
PartialEmojiOnlyId,
186186
Emoji,
187187
PartialEmoji,
188+
Awaitable,
188189
} from '.';
189190
import { expectAssignable, expectNotAssignable, expectNotType, expectType } from 'tsd';
190191
import type { ContextMenuCommandBuilder, SlashCommandBuilder } from '@discordjs/builders';
@@ -412,7 +413,7 @@ client.on('messageCreate', async message => {
412413
(
413414
test: ButtonInteraction<'cached'>,
414415
items: Collection<Snowflake, ButtonInteraction<'cached'>>,
415-
) => boolean | Promise<boolean>
416+
) => Awaitable<boolean>
416417
>(buttonCollector.filter);
417418
expectType<GuildTextBasedChannel>(message.channel);
418419
expectType<Guild>(message.guild);

packages/rest/src/lib/utils/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Readable } from 'node:stream';
22
import type { ReadableStream } from 'node:stream/web';
33
import type { Collection } from '@discordjs/collection';
4+
import type { Awaitable } from '@discordjs/util';
45
import type { Agent, Dispatcher, RequestInit, BodyInit, Response } from 'undici';
56
import type { IHandler } from '../interfaces/Handler.js';
67

@@ -183,7 +184,7 @@ export interface RateLimitData {
183184
/**
184185
* A function that determines whether the rate limit hit should throw an Error
185186
*/
186-
export type RateLimitQueueFilter = (rateLimitData: RateLimitData) => Promise<boolean> | boolean;
187+
export type RateLimitQueueFilter = (rateLimitData: RateLimitData) => Awaitable<boolean>;
187188

188189
export interface APIRequest {
189190
/**

0 commit comments

Comments
 (0)