Skip to content

Commit 6404c01

Browse files
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>
1 parent c50809e commit 6404c01

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,8 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
955955
private _eval(script: string): unknown;
956956
private _validateOptions(options: ClientOptions): void;
957957
private get _censoredToken(): string | null;
958+
// This a technique used to brand the ready state. Or else we'll get `never` errors on typeguard checks.
959+
private readonly _ready: Ready;
958960

959961
public application: If<Ready, ClientApplication>;
960962
public channels: ChannelManager;

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,12 @@ const client: Client = new Client({
197197
}),
198198
});
199199

200+
if (client.isReady()) {
201+
expectType<Client<true>>(client);
202+
} else {
203+
expectType<Client>(client);
204+
}
205+
200206
const testGuildId = '222078108977594368'; // DJS
201207
const testUserId = '987654321098765432'; // example id
202208
const globalCommandId = '123456789012345678'; // example id

0 commit comments

Comments
 (0)