Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types: use wrapper utilities #9945

Merged
merged 3 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ export abstract class Collector<Key, Value, Extras extends unknown[] = []> exten
public toJSON(): unknown;

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

public on<EventKey extends keyof CollectorEventTypes<Key, Value, Extras>>(
Expand Down Expand Up @@ -5066,7 +5066,7 @@ export interface CloseEvent {
reason: string;
}

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

export interface CollectorOptions<FilterArguments extends unknown[]> {
filter?: CollectorFilter<FilterArguments>;
Expand Down Expand Up @@ -6647,7 +6647,7 @@ export type Serialized<Value> = Value extends symbol | bigint | (() => any)
? never
: Value extends number | string | boolean | undefined
? Value
: Value extends { toJSON(): infer JSONResult }
: Value extends JSONEncodable<infer JSONResult>
? JSONResult
: Value extends ReadonlyArray<infer ItemType>
? Serialized<ItemType>[]
Expand Down
3 changes: 2 additions & 1 deletion packages/discord.js/typings/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ import {
PartialEmojiOnlyId,
Emoji,
PartialEmoji,
Awaitable,
} from '.';
import { expectAssignable, expectNotAssignable, expectNotType, expectType } from 'tsd';
import type { ContextMenuCommandBuilder, SlashCommandBuilder } from '@discordjs/builders';
Expand Down Expand Up @@ -412,7 +413,7 @@ client.on('messageCreate', async message => {
(
test: ButtonInteraction<'cached'>,
items: Collection<Snowflake, ButtonInteraction<'cached'>>,
) => boolean | Promise<boolean>
) => Awaitable<boolean>
>(buttonCollector.filter);
expectType<GuildTextBasedChannel>(message.channel);
expectType<Guild>(message.guild);
Expand Down
3 changes: 2 additions & 1 deletion packages/rest/src/lib/utils/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Readable } from 'node:stream';
import type { ReadableStream } from 'node:stream/web';
import type { Collection } from '@discordjs/collection';
import type { Awaitable } from '@discordjs/util';
import type { Agent, Dispatcher, RequestInit, BodyInit, Response } from 'undici';
import type { IHandler } from '../interfaces/Handler.js';

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

export interface APIRequest {
/**
Expand Down