From 4d54877c1033b792d528cbc8bb1cd2d7f8ed2d6e Mon Sep 17 00:00:00 2001 From: n1ck_pro <59617443+N1ckPro@users.noreply.github.com> Date: Sun, 10 Sep 2023 13:49:00 +0200 Subject: [PATCH] types(Client): fix isReady narrowing (#9828) * types(Client): fix isReady narrowing * chore: add requested changes * chore: test both ready cases --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- packages/discord.js/typings/index.d.ts | 2 ++ packages/discord.js/typings/index.test-d.ts | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 8119271dec5c..1c22ecc3d8be 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -955,6 +955,8 @@ export class Client extends BaseClient { private _eval(script: string): unknown; private _validateOptions(options: ClientOptions): void; private get _censoredToken(): string | null; + // This a technique used to brand the ready state. Or else we'll get `never` errors on typeguard checks. + private readonly _ready: Ready; public application: If; public channels: ChannelManager; diff --git a/packages/discord.js/typings/index.test-d.ts b/packages/discord.js/typings/index.test-d.ts index 86b28249e6b0..026e2f80794a 100644 --- a/packages/discord.js/typings/index.test-d.ts +++ b/packages/discord.js/typings/index.test-d.ts @@ -197,6 +197,12 @@ const client: Client = new Client({ }), }); +if (client.isReady()) { + expectType>(client); +} else { + expectType(client); +} + const testGuildId = '222078108977594368'; // DJS const testUserId = '987654321098765432'; // example id const globalCommandId = '123456789012345678'; // example id