Skip to content

Commit

Permalink
types: use wrapper utilities (#9945)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
kyranet and kodiakhq[bot] committed Nov 12, 2023
1 parent cc07a28 commit 4bc1dae
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
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

0 comments on commit 4bc1dae

Please sign in to comment.