InteractionOptionResolver pleasing TypeScript

I have an HTTP interactions app that utilizes @discordjs/core/http-only. Currently, I have my own class for resolving application command options, however I'd like to use the one provided by @sapphire/discord-utilities. The only setback I'm having is passing the interaction to a new instance of InteractionOptionResolver. Its constructor is typed as
constructor(interaction: APIApplicationCommandInteraction | APIApplicationCommandAutocompleteInteraction | APIModalSubmitInteraction)
constructor(interaction: APIApplicationCommandInteraction | APIApplicationCommandAutocompleteInteraction | APIModalSubmitInteraction)
However when I give it a variable typed as APIApplicationCommandInteraction which I thought would work given its type definition includes it, I get a nasty error of it missing a target_id, which I know stems from context menu command-related stuff. I get similar missing property errors with APIContextMenuInteraction or APIChatInputApplicationCommandInteraction - yada yada missing users property or just not assignable at all. My question is, before I go casting or @ts-ignoreing or whatnot, is there any realistic way to resolve these errors so I can use this utility class in TypeScript? Am I missing some simple step? Is this just TypeScript limitations? Node: v18.17.0 @discordjs/core: v1.1.1 @saphhire/discord-utilities: v3.2.3 discord-api-types (@discordjs/core): v0.37.61 discord-api-types (@sapphire/discord-utilities): v0.37.76 typescript: v5.4.3 Code sample: https://gist.github.com/TAEMBO/39fbdbb6b460989f84aa57386d1743ce Code sample and contents of tsc error provided via attached screenshots as well
No description
No description
Solution:
Can you try forcing the discord-api-types version through package resolutions / overwrites?
Jump to solution
14 Replies
Solution
Favna
Favna8mo ago
Can you try forcing the discord-api-types version through package resolutions / overwrites?
Favna
Favna8mo ago
Should also mention if you want a sapphire framework like experience but for an http only bot you could use
Spinel
Spinel8mo ago
@skyra/http-framework
The framework for ArchId Network's HTTP-only bots ❯ Author: skyra-project ❯ Maintainers: favna and kyranet ❯ Latest version: 2.1.0 ❯ License: Apache-2.0 ❯ Date Created: <t:1647179883:d> ❯ Date Modified: <t:1704912291:d> Dependencies: @discordjs/builders, @discordjs/collection, @discordjs/rest, @discordjs/util, @sapphire/pieces, @sapphire/result, @sapphire/utilities, @vladfrangu/async_event_emitter, and discord-api-types
Favna
Favna8mo ago
It's what powers @Spinel , @Teryl , @Nekokai , @Iriss , and a few other bots that are not in this server (all of those mentioned are open source too)
TÆMBØØ
TÆMBØØ8mo ago
Added an override for @sapphire/discord-utilities to the version that @discordjs/core is using (v0.37.61) and that seems to have resolved the issue. Seems like it's just some discrepancies in versions that I didn't think of. In any case, cheers for the help on this Not sure how to close the post myself per guidelines, so uhh... yea, this can be closed
Youssef
Youssef5mo ago
@Boomeravna, Hey, what version should i force to?
Favna
Favna5mo ago
see the last message from TAEMBO above, that said, this post is also outdated and there have been quite a few versions in between then and now
Youssef
Youssef5mo ago
yes but doing what he did, didn't work for me
Youssef
Youssef5mo ago
No description
Youssef
Youssef5mo ago
Node: v18.16.1
Favna
Favna5mo ago
First of all, what package manager are you using because resolutions are only valid for yarn and pnpm. Secondly, like I said, there have been many versions since March and the actual version to use now is https://github.com/discordjs/discord.js/blob/311aaf26058c7a95f6d973686e49818c9ecb0fb1/packages/builders/package.json#L71
Youssef
Youssef5mo ago
npm
Youssef
Youssef5mo ago
yes i did that, thanks
Want results from more Discord servers?
Add your server