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>
This commit is contained in:
n1ck_pro
2023-09-10 13:49:00 +02:00
committed by GitHub
parent c50809e206
commit 6404c013e7
2 changed files with 8 additions and 0 deletions

View File

@@ -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;

View File

@@ -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