Properly Defining Types for Interactions

Currently migrating my bot from JS(v13) -> TS(v14.3.0) and I've run into a challenge perhaps, I am attempting to call a function and pass the Interaction<> or ChatInputCommandInteraction<CacheType> type to the parameter however it doesn't think its the correct type? Am I just blind and using the wrong type to pass?
9 Replies
d.js docs
d.js docs3y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
txj
txjOP3y ago
constructor(client: Bot) {
super();
this.client.on('interactionCreate', (interaction): Promise<any> => this.exec(interaction)); // Argument of type 'Interaction<CacheType>' is not assignable to parameter of type 'ChatInputCommandInteraction<CacheType>'.......
}

// exec
async exec(interaction: ChatInputCommandInteraction<CacheType>): Promise<any> { ... }
constructor(client: Bot) {
super();
this.client.on('interactionCreate', (interaction): Promise<any> => this.exec(interaction)); // Argument of type 'Interaction<CacheType>' is not assignable to parameter of type 'ChatInputCommandInteraction<CacheType>'.......
}

// exec
async exec(interaction: ChatInputCommandInteraction<CacheType>): Promise<any> { ... }
video testing types
txj
txjOP3y ago
So since typescript is set to strict, I presume i should just allow this as an interaction: unknown type? seems either one I pick TS doesnt like it because its top level coming from the event perhaps my tsconfig.json is too strict True, this is specifically handling all Interaction aliases but yeah TSS either wants a specific or not
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
txj
txjOP3y ago
Hmm see im new to TS sorry thanks for the advice ill keep researching i see the methods on that one yea I understand that, but typescript appears to be taking it literally unless I dont understand how aliases work which is very likely
txj
txjOP3y ago
it exists in ChatInputCommandInteraction for .reply() so i guess i need to add the others oh i see interesting thanks sorry mate closing this, appreciate it apologies for lack of knowledge pepperSprayLaugh
Want results from more Discord servers?
Add your server