Interaction type is too narrow

Currently the Interaction type is:
export type Interaction<Cached extends CacheType = CacheType> =
| ChatInputCommandInteraction<Cached>
| MessageContextMenuCommandInteraction<Cached>
| UserContextMenuCommandInteraction<Cached>
| SelectMenuInteraction<Cached>
| ButtonInteraction<Cached>
| AutocompleteInteraction<Cached>
| ModalSubmitInteraction<Cached>;
export type Interaction<Cached extends CacheType = CacheType> =
| ChatInputCommandInteraction<Cached>
| MessageContextMenuCommandInteraction<Cached>
| UserContextMenuCommandInteraction<Cached>
| SelectMenuInteraction<Cached>
| ButtonInteraction<Cached>
| AutocompleteInteraction<Cached>
| ModalSubmitInteraction<Cached>;
I'm creating a function that takes an Interaction as a parameter, but typescript is reporting errors because the type is too narrow. In my case, I'm trying to input a ContextMenuCommandInteraction, but the type requires either a MessageContextMenuCommandInteraction or UserContextMenuCommandInteraction. Is there any way to use a general ContextMenuCommandInteraction with passing it in like:
someFunction(interaction as MessageContextMenuCommandInteraction | UserContextMenuCommandInteraction);
someFunction(interaction as MessageContextMenuCommandInteraction | UserContextMenuCommandInteraction);
Every time?
3 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Siris
Siris2y ago
@lioness100 are you getting this interaction from the djs interaction create event?
Lioness100
Lioness1002y ago
No, but I resolved the problem thanks for your help. I realized I was being silly and didn't need to cast as either context menu type when I could just cast as Interaction