why set event return type to void instead of any?

Client.on("messageCreate", async (Message) => {
let isWrongAns = ...

if (isWrongAns) return await Message.channel.send("wrong answer");
})
Client.on("messageCreate", async (Message) => {
let isWrongAns = ...

if (isWrongAns) return await Message.channel.send("wrong answer");
})
typescript error (simplified):
the "messageCreate" event's expected return type is Promise<void>. But since you are returning a Message, i am giving you this error
the "messageCreate" event's expected return type is Promise<void>. But since you are returning a Message, i am giving you this error
i didnt use typescript before djs v14 but why not set the type to Promise<any>? is there a specific reason
11 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Parogo_72
Parogo_723y ago
Unless im missing something, arent you the one that can change what the function will expect to receive? If you want to to receive Promise<any>, just put it
potsu
potsuOP3y ago
im sorry i dont get what do u mean
Parogo_72
Parogo_723y ago
(param1, param2): returnType => {}
potsu
potsuOP3y ago
u mean changing the callback to something like
Client.on("messageCreate", async function (Message): Promise<any> {
let isWrongAns = ...

if (isWrongAns) return await Message.channel.send("wrong answer") as any as Promise<any>;
})
Client.on("messageCreate", async function (Message): Promise<any> {
let isWrongAns = ...

if (isWrongAns) return await Message.channel.send("wrong answer") as any as Promise<any>;
})
Parogo_72
Parogo_723y ago
Just use Promise<any>...
potsu
potsuOP3y ago
yea mb i typed wrong but thats just unnecessary complication
Parogo_72
Parogo_723y ago
Doubt you need as any as Promise<any> Else you can also do Promise<Message> if you will always return a message
potsu
potsuOP3y ago
but that wont go with the event's expected return do u want me to show u what the error says? its long na i do need it
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Kinect3000
Kinect30003y ago
Use void if you want to make ts happy return void await …
Want results from more Discord servers?
Add your server