wehmoen
wehmoen
DIAdiscord.js - Imagine an app
Created by wehmoen on 1/2/2024 in #djs-questions
Some typescript error when updating components
Hello there 👋🏻 I created a bot that handles a component interaction - a button click. OnClick I use ActionRowBuilder to create an updated row object and then send the update by using:
const updatedRow = new ActionRowBuilder()
.addComponents(
new ButtonBuilder().setLabel("Continue").setStyle(ButtonStyle.Success).setCustomId("gen_continue").setDisabled(true),
new ButtonBuilder().setLabel("Cancel").setStyle(ButtonStyle.Danger).setCustomId("gen_cancel").setDisabled(true),
)


await interaction.update({
components: [
updatedRow
]
})
const updatedRow = new ActionRowBuilder()
.addComponents(
new ButtonBuilder().setLabel("Continue").setStyle(ButtonStyle.Success).setCustomId("gen_continue").setDisabled(true),
new ButtonBuilder().setLabel("Cancel").setStyle(ButtonStyle.Danger).setCustomId("gen_cancel").setDisabled(true),
)


await interaction.update({
components: [
updatedRow
]
})
But unless I add a @ts-ignore above the updatedRow in the components array my TS won't compile - With the @ts-ignore it not just only compiles - it also works. The buttons are disabled. Thisis the typehints my IDE (WebStorm) gives me:
TS2769: No overload matches this call.
Overload 1 of 2,
(options: InteractionUpdateOptions & { fetchReply: true; }): Promise<Message<boolean>>
, gave the following error.
Type ActionRowBuilder<AnyComponentBuilder> is not assignable to type
APIActionRowComponent<APIMessageActionRowComponent> | JSONEncodable<APIActionRowComponent<APIMessageActionRowComponent>> | ActionRowData<...>
Property type is missing in type ActionRowBuilder<AnyComponentBuilder> but required in type
ActionRowData<MessageActionRowComponentBuilder | MessageActionRowComponentData>
Overload 2 of 2,
(options: string | MessagePayload | InteractionUpdateOptions): Promise<InteractionResponse<boolean>>
, gave the following error.
Type ActionRowBuilder<AnyComponentBuilder> is not assignable to type
APIActionRowComponent<APIMessageActionRowComponent> | JSONEncodable<APIActionRowComponent<APIMessageActionRowComponent>> | ActionRowData<...>
index.d.ts(283, 3): type is declared here.
TS2769: No overload matches this call.
Overload 1 of 2,
(options: InteractionUpdateOptions & { fetchReply: true; }): Promise<Message<boolean>>
, gave the following error.
Type ActionRowBuilder<AnyComponentBuilder> is not assignable to type
APIActionRowComponent<APIMessageActionRowComponent> | JSONEncodable<APIActionRowComponent<APIMessageActionRowComponent>> | ActionRowData<...>
Property type is missing in type ActionRowBuilder<AnyComponentBuilder> but required in type
ActionRowData<MessageActionRowComponentBuilder | MessageActionRowComponentData>
Overload 2 of 2,
(options: string | MessagePayload | InteractionUpdateOptions): Promise<InteractionResponse<boolean>>
, gave the following error.
Type ActionRowBuilder<AnyComponentBuilder> is not assignable to type
APIActionRowComponent<APIMessageActionRowComponent> | JSONEncodable<APIActionRowComponent<APIMessageActionRowComponent>> | ActionRowData<...>
index.d.ts(283, 3): type is declared here.
This all happens directly in the event handler for InteractionCreate with this signature: async function handler(interaction: Interaction): Promise<any> I am unsure if my handler signature is wrong or if this is actually something with the library. Could someone take a look?
4 replies