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>
This commit is contained in:
Aura 2023-11-12 22:40:59 +01:00 committed by GitHub
parent cc07a28f12
commit 4bc1dae36f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 5 deletions

View file

@ -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>>(
@ -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>;
@ -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>[]

View file

@ -185,6 +185,7 @@ import {
PartialEmojiOnlyId,
Emoji,
PartialEmoji,
Awaitable,
} from '.';
import { expectAssignable, expectNotAssignable, expectNotType, expectType } from 'tsd';
import type { ContextMenuCommandBuilder, SlashCommandBuilder } from '@discordjs/builders';
@ -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);

View file

@ -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';
@ -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 {
/**