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 User2y ago
Message Not Public
Sign In & Join Server To View
Parogo_72
Parogo_722y 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
potsu2y ago
im sorry i dont get what do u mean
Parogo_72
Parogo_722y ago
(param1, param2): returnType => {}
potsu
potsu2y 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_722y ago
Just use Promise<any>...
potsu
potsu2y ago
yea mb i typed wrong but thats just unnecessary complication
Parogo_72
Parogo_722y ago
Doubt you need as any as Promise<any> Else you can also do Promise<Message> if you will always return a message
potsu
potsu2y 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 User2y ago
Message Not Public
Sign In & Join Server To View
Kinect3000
Kinect30002y ago
Use void if you want to make ts happy return void await …