mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-19 21:13:30 +01:00
feat(Client): add conditional ready typings (#6073)
This commit is contained in:
@@ -5,6 +5,8 @@ import {
|
||||
ApplicationCommandResolvable,
|
||||
CategoryChannel,
|
||||
Client,
|
||||
ClientApplication,
|
||||
ClientUser,
|
||||
Collection,
|
||||
Constants,
|
||||
DMChannel,
|
||||
@@ -447,6 +449,27 @@ client.on('interaction', async interaction => {
|
||||
|
||||
client.login('absolutely-valid-token');
|
||||
|
||||
// Test client conditional types
|
||||
client.on('ready', client => {
|
||||
assertType<Client<true>>(client);
|
||||
});
|
||||
|
||||
declare const loggedInClient: Client<true>;
|
||||
assertType<ClientApplication>(loggedInClient.application);
|
||||
assertType<Date>(loggedInClient.readyAt);
|
||||
assertType<number>(loggedInClient.readyTimestamp);
|
||||
assertType<string>(loggedInClient.token);
|
||||
assertType<number>(loggedInClient.uptime);
|
||||
assertType<ClientUser>(loggedInClient.user);
|
||||
|
||||
declare const loggedOutClient: Client<false>;
|
||||
assertType<null>(loggedOutClient.application);
|
||||
assertType<null>(loggedOutClient.readyAt);
|
||||
assertType<null>(loggedOutClient.readyTimestamp);
|
||||
assertType<string | null>(loggedOutClient.token);
|
||||
assertType<null>(loggedOutClient.uptime);
|
||||
assertType<null>(loggedOutClient.user);
|
||||
|
||||
// Test type transformation:
|
||||
declare const assertType: <T>(value: T) => asserts value is T;
|
||||
declare const serialize: <T>(value: T) => Serialized<T>;
|
||||
|
||||
Reference in New Issue
Block a user