elektron
elektron
DIAdiscord.js - Imagine an app
Created by elektron on 1/13/2024 in #djs-questions
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
7 replies