mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 20:43:30 +01:00
types: don't allow any object in the first parameter if second parameter is not given in TextBasedChannel#send (#4736)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/// <reference path="index.d.ts" />
|
||||
|
||||
import { Client } from 'discord.js';
|
||||
import { Client, Message, MessageAttachment, MessageEmbed } from 'discord.js';
|
||||
|
||||
const client: Client = new Client();
|
||||
|
||||
@@ -25,4 +25,29 @@ client.on('messageReactionRemoveAll', async message => {
|
||||
console.log(`messageReactionRemoveAll - content: ${message.content}`);
|
||||
});
|
||||
|
||||
// These are to check that stuff is the right type
|
||||
declare const assertIsMessage: (m: Promise<Message>) => void;
|
||||
declare const assertIsMessageArray: (m: Promise<Message[]>) => void;
|
||||
|
||||
client.on('message', ({ channel }) => {
|
||||
assertIsMessage(channel.send('string'));
|
||||
assertIsMessage(channel.send({}));
|
||||
assertIsMessage(channel.send({ embed: {} }));
|
||||
assertIsMessage(channel.send({ another: 'property' }, {}));
|
||||
|
||||
const attachment = new MessageAttachment('file.png');
|
||||
const embed = new MessageEmbed();
|
||||
assertIsMessage(channel.send(attachment));
|
||||
assertIsMessage(channel.send(embed));
|
||||
assertIsMessage(channel.send([attachment, embed]));
|
||||
|
||||
assertIsMessageArray(channel.send(Symbol('another primitive'), { split: true }));
|
||||
assertIsMessageArray(channel.send({ split: true }));
|
||||
|
||||
// @ts-expect-error
|
||||
channel.send();
|
||||
// @ts-expect-error
|
||||
channel.send({ another: 'property' });
|
||||
});
|
||||
|
||||
client.login('absolutely-valid-token');
|
||||
|
||||
Reference in New Issue
Block a user