#Interaction type is too narrow

8 messages · Page 1 of 1 (latest)

cold heath
#

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>;

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);

Every time?

orchid kestrel
#

• 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.

mint barn
#

Where do you get the ContextMenuInteraction from?

orchid kestrel
#

anyways you can make a custom type for that

#
type customcontextmenucommandinteraction = MessageContextMenuCommandInteraction | UserContextMenuCommandInteraction
mint barn
carmine forum
#

@cold heath are you getting this interaction from the djs interaction create event?