Skip to content

Commit

Permalink
types(Client): fix isReady narrowing (#9828)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
N1ckPro and kodiakhq[bot] committed Sep 10, 2023
1 parent c50809e commit 6404c01
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,8 @@ export class Client<Ready extends boolean = boolean> 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<Ready, ClientApplication>;
public channels: ChannelManager;
Expand Down
6 changes: 6 additions & 0 deletions packages/discord.js/typings/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ const client: Client = new Client({
}),
});

if (client.isReady()) {
expectType<Client<true>>(client);
} else {
expectType<Client>(client);
}

const testGuildId = '222078108977594368'; // DJS
const testUserId = '987654321098765432'; // example id
const globalCommandId = '123456789012345678'; // example id
Expand Down

0 comments on commit 6404c01

Please sign in to comment.