Issue with types

So I created a function for myself to manipulate the content of my responses, but i'm having issues with that:
type sendAnyMessage = string | MessageReplyOptions | MessagePayload | MessageCreateOptions | InteractionReplyOptions | (InteractionReplyOptions & { fetchReply: true });
type result = Promise<Message | InteractionResponse>
type otherComp = Omit<sendAnyMessage, "content" | "embeds">

export async function sendTip(
content: string | EmbedBuilder | APIEmbed | EmbedBuilder[] | APIEmbed[] | (APIEmbed | EmbedBuilder)[],
func: (content: sendAnyMessage) => result,
otherComponents: otherComp | null = null
): result {
// function code
}
type sendAnyMessage = string | MessageReplyOptions | MessagePayload | MessageCreateOptions | InteractionReplyOptions | (InteractionReplyOptions & { fetchReply: true });
type result = Promise<Message | InteractionResponse>
type otherComp = Omit<sendAnyMessage, "content" | "embeds">

export async function sendTip(
content: string | EmbedBuilder | APIEmbed | EmbedBuilder[] | APIEmbed[] | (APIEmbed | EmbedBuilder)[],
func: (content: sendAnyMessage) => result,
otherComponents: otherComp | null = null
): result {
// function code
}
and this is how im using it:
sendTip(embed, interaction.reply, { fetchReply: true })
sendTip(embed, interaction.reply, { fetchReply: true })
But I get the following error:
Argument of type '{ (options: InteractionReplyOptions & { fetchReply: true; }): Promise<Message<boolean>>; (options: string | MessagePayload | InteractionReplyOptions): Promise<...>; }' is not assignable to parameter of type '(content: sendAnyMessage) => result'.
Types of parameters 'options' and 'content' are incompatible.
Type 'sendAnyMessage' is not assignable to type 'InteractionReplyOptions & { fetchReply: true; }'.
Type 'string' is not assignable to type 'InteractionReplyOptions & { fetchReply: true; }'.
Type 'string' is not assignable to type '{ fetchReply: true; }'.ts(2345)
Argument of type '{ (options: InteractionReplyOptions & { fetchReply: true; }): Promise<Message<boolean>>; (options: string | MessagePayload | InteractionReplyOptions): Promise<...>; }' is not assignable to parameter of type '(content: sendAnyMessage) => result'.
Types of parameters 'options' and 'content' are incompatible.
Type 'sendAnyMessage' is not assignable to type 'InteractionReplyOptions & { fetchReply: true; }'.
Type 'string' is not assignable to type 'InteractionReplyOptions & { fetchReply: true; }'.
Type 'string' is not assignable to type '{ fetchReply: true; }'.ts(2345)
I'm not that much of an expert in ts, so this error has made me stumped
2 Replies
d.js toolkit
d.js toolkit5mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by staff
elektron
elektron5mo ago
- DJS v14.4.1 - dont know if this is related, but i'll try to give it a shot here I guess my best bet is to make the function return the manipulated data, then use that for my interaction.reply? The thing is i need to specifiy what method it could be, like it could message.reply, channel.send, interaction.editReply I see Then it makes more sense for the function to just return the manipulated embed / content instead