mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 02:53:31 +01:00
fix(Sharding): strict type context and return (#5933)
This commit is contained in:
@@ -1,6 +1,17 @@
|
||||
/// <reference path="index.d.ts" />
|
||||
|
||||
import { Client, Intents, Message, MessageAttachment, MessageEmbed } from 'discord.js';
|
||||
import {
|
||||
Client,
|
||||
Collection,
|
||||
Intents,
|
||||
Message,
|
||||
MessageAttachment,
|
||||
MessageEmbed,
|
||||
Permissions,
|
||||
Serialized,
|
||||
ShardClientUtil,
|
||||
ShardingManager,
|
||||
} from 'discord.js';
|
||||
|
||||
const client: Client = new Client({
|
||||
intents: Intents.NON_PRIVILEGED,
|
||||
@@ -48,3 +59,42 @@ client.on('message', ({ channel }) => {
|
||||
});
|
||||
|
||||
client.login('absolutely-valid-token');
|
||||
|
||||
// Test type transformation:
|
||||
declare const assertType: <T>(value: T) => asserts value is T;
|
||||
declare const serialize: <T>(value: T) => Serialized<T>;
|
||||
|
||||
assertType<undefined>(serialize(undefined));
|
||||
assertType<null>(serialize(null));
|
||||
assertType<number[]>(serialize([1, 2, 3]));
|
||||
assertType<{}>(serialize(new Set([1, 2, 3])));
|
||||
assertType<{}>(
|
||||
serialize(
|
||||
new Map([
|
||||
[1, '2'],
|
||||
[2, '4'],
|
||||
]),
|
||||
),
|
||||
);
|
||||
assertType<string>(serialize(new Permissions(Permissions.FLAGS.ATTACH_FILES)));
|
||||
assertType<number>(serialize(new Intents(Intents.FLAGS.GUILDS)));
|
||||
assertType<unknown>(
|
||||
serialize(
|
||||
new Collection([
|
||||
[1, '2'],
|
||||
[2, '4'],
|
||||
]),
|
||||
),
|
||||
);
|
||||
assertType<never>(serialize(Symbol('a')));
|
||||
assertType<never>(serialize(() => {}));
|
||||
assertType<never>(serialize(BigInt(42)));
|
||||
|
||||
// Test type return of broadcastEval:
|
||||
declare const shardClientUtil: ShardClientUtil;
|
||||
declare const shardingManager: ShardingManager;
|
||||
|
||||
assertType<Promise<number[]>>(shardingManager.broadcastEval(() => 1));
|
||||
assertType<Promise<number[]>>(shardClientUtil.broadcastEval(() => 1));
|
||||
assertType<Promise<number[]>>(shardingManager.broadcastEval(async () => 1));
|
||||
assertType<Promise<number[]>>(shardClientUtil.broadcastEval(async () => 1));
|
||||
|
||||
Reference in New Issue
Block a user