feat: add isModalSubmitInteraction() type guard (#1428)

* Implement type-guard for modal submit interactions

Added a type-guard function to check for modal submit interactions.

* Implement missing isModalSubmitInteraction typeguard in deno types

Added a type-guard function to check for modal submit interactions in deno types because I missed that before.

* fix(typings): replace 'type-guard' with 'type guard'

This corrects the spacing in the term across multiple locations for consistency with standard TypeScript terminology.

* Revert "fix(typings): replace 'type-guard' with 'type guard'"

This reverts commit 822b2e0bbc.

* fix(typings): replace 'type-guard' with 'type guard' in jsdoc comments in v10

* fix(typings): update JSDoc comments to use 'type guard' instead of 'type-guard'

* fix(typings): replace "type-guard" with "type guard" in v9 utils

* feat(interactions): add type guard for modal submit interactions in v9

---------

Co-authored-by: Luca Hentschel <luca.hentschel@2peaches.de>
This commit is contained in:
LukeZ
2025-11-10 14:59:15 +01:00
committed by GitHub
parent 117b63dcd0
commit f883770df6
4 changed files with 104 additions and 52 deletions

39
deno/utils/v10.ts generated
View File

@@ -15,13 +15,14 @@ import type {
APIMessageComponentGuildInteraction,
APIMessageComponentInteraction,
APIMessageComponentSelectMenuInteraction,
APIModalSubmitInteraction,
} from '../payloads/v10/mod.ts';
import { ApplicationCommandType, ButtonStyle, ComponentType, InteractionType } from '../payloads/v10/mod.ts';
// Interactions
/**
* A type-guard check for DM interactions
* A type guard check for DM interactions
*
* @param interaction - The interaction to check against
* @returns A boolean that indicates if the interaction was received in a DM channel
@@ -31,7 +32,7 @@ export function isDMInteraction(interaction: APIInteraction): interaction is API
}
/**
* A type-guard check for guild interactions
* A type guard check for guild interactions
*
* @param interaction - The interaction to check against
* @returns A boolean that indicates if the interaction was received in a guild
@@ -43,7 +44,7 @@ export function isGuildInteraction(interaction: APIInteraction): interaction is
// ApplicationCommandInteractions
/**
* A type-guard check for DM application command interactions
* A type guard check for DM application command interactions
*
* @param interaction - The application command interaction to check against
* @returns A boolean that indicates if the application command interaction was received in a DM channel
@@ -55,7 +56,7 @@ export function isApplicationCommandDMInteraction(
}
/**
* A type-guard check for guild application command interactions
* A type guard check for guild application command interactions
*
* @param interaction - The interaction to check against
* @returns A boolean that indicates if the application command interaction was received in a guild
@@ -69,7 +70,7 @@ export function isApplicationCommandGuildInteraction(
// MessageComponentInteractions
/**
* A type-guard check for DM message component interactions
* A type guard check for DM message component interactions
*
* @param interaction - The message component interaction to check against
* @returns A boolean that indicates if the message component interaction was received in a DM channel
@@ -81,7 +82,7 @@ export function isMessageComponentDMInteraction(
}
/**
* A type-guard check for guild message component interactions
* A type guard check for guild message component interactions
*
* @param interaction - The interaction to check against
* @returns A boolean that indicates if the message component interaction was received in a guild
@@ -95,7 +96,7 @@ export function isMessageComponentGuildInteraction(
// Buttons
/**
* A type-guard check for buttons that have a `url` attached to them.
* A type guard check for buttons that have a `url` attached to them.
*
* @param component - The button to check against
* @returns A boolean that indicates if the button has a `url` attached to it
@@ -105,7 +106,7 @@ export function isLinkButton(component: APIButtonComponent): component is APIBut
}
/**
* A type-guard check for buttons that have a `custom_id` attached to them.
* A type guard check for buttons that have a `custom_id` attached to them.
*
* @param component - The button to check against
* @returns A boolean that indicates if the button has a `custom_id` attached to it
@@ -114,10 +115,22 @@ export function isInteractionButton(component: APIButtonComponent): component is
return ![ButtonStyle.Link, ButtonStyle.Premium].includes(component.style);
}
// Modal
/**
* A type guard check for modals submit interactions
*
* @param interaction - The interaction to check against
* @returns A boolean that indicates if the interaction is a modal submission
*/
export function isModalSubmitInteraction(interaction: APIInteraction): interaction is APIModalSubmitInteraction {
return interaction.type === InteractionType.ModalSubmit;
}
// Message Components
/**
* A type-guard check for message component interactions
* A type guard check for message component interactions
*
* @param interaction - The interaction to check against
* @returns A boolean that indicates if the interaction is a message component
@@ -129,7 +142,7 @@ export function isMessageComponentInteraction(
}
/**
* A type-guard check for button message component interactions
* A type guard check for button message component interactions
*
* @param interaction - The message component interaction to check against
* @returns A boolean that indicates if the message component is a button
@@ -141,7 +154,7 @@ export function isMessageComponentButtonInteraction(
}
/**
* A type-guard check for select menu message component interactions
* A type guard check for select menu message component interactions
*
* @param interaction - The message component interaction to check against
* @returns A boolean that indicates if the message component is a select menu
@@ -161,7 +174,7 @@ export function isMessageComponentSelectMenuInteraction(
// Application Commands
/**
* A type-guard check for chat input application commands.
* A type guard check for chat input application commands.
*
* @param interaction - The interaction to check against
* @returns A boolean that indicates if the interaction is a chat input application command
@@ -173,7 +186,7 @@ export function isChatInputApplicationCommandInteraction(
}
/**
* A type-guard check for context menu application commands.
* A type guard check for context menu application commands.
*
* @param interaction - The interaction to check against
* @returns A boolean that indicates if the interaction is a context menu application command

39
deno/utils/v9.ts generated
View File

@@ -15,13 +15,14 @@ import type {
APIMessageComponentGuildInteraction,
APIMessageComponentInteraction,
APIMessageComponentSelectMenuInteraction,
APIModalSubmitInteraction,
} from '../payloads/v9/mod.ts';
import { ApplicationCommandType, ButtonStyle, ComponentType, InteractionType } from '../payloads/v9/mod.ts';
// Interactions
/**
* A type-guard check for DM interactions
* A type guard check for DM interactions
*
* @param interaction - The interaction to check against
* @returns A boolean that indicates if the interaction was received in a DM channel
@@ -31,7 +32,7 @@ export function isDMInteraction(interaction: APIInteraction): interaction is API
}
/**
* A type-guard check for guild interactions
* A type guard check for guild interactions
*
* @param interaction - The interaction to check against
* @returns A boolean that indicates if the interaction was received in a guild
@@ -43,7 +44,7 @@ export function isGuildInteraction(interaction: APIInteraction): interaction is
// ApplicationCommandInteractions
/**
* A type-guard check for DM application command interactions
* A type guard check for DM application command interactions
*
* @param interaction - The application command interaction to check against
* @returns A boolean that indicates if the application command interaction was received in a DM channel
@@ -55,7 +56,7 @@ export function isApplicationCommandDMInteraction(
}
/**
* A type-guard check for guild application command interactions
* A type guard check for guild application command interactions
*
* @param interaction - The interaction to check against
* @returns A boolean that indicates if the application command interaction was received in a guild
@@ -69,7 +70,7 @@ export function isApplicationCommandGuildInteraction(
// MessageComponentInteractions
/**
* A type-guard check for DM message component interactions
* A type guard check for DM message component interactions
*
* @param interaction - The message component interaction to check against
* @returns A boolean that indicates if the message component interaction was received in a DM channel
@@ -81,7 +82,7 @@ export function isMessageComponentDMInteraction(
}
/**
* A type-guard check for guild message component interactions
* A type guard check for guild message component interactions
*
* @param interaction - The interaction to check against
* @returns A boolean that indicates if the message component interaction was received in a guild
@@ -95,7 +96,7 @@ export function isMessageComponentGuildInteraction(
// Buttons
/**
* A type-guard check for buttons that have a `url` attached to them.
* A type guard check for buttons that have a `url` attached to them.
*
* @param component - The button to check against
* @returns A boolean that indicates if the button has a `url` attached to it
@@ -105,7 +106,7 @@ export function isLinkButton(component: APIButtonComponent): component is APIBut
}
/**
* A type-guard check for buttons that have a `custom_id` attached to them.
* A type guard check for buttons that have a `custom_id` attached to them.
*
* @param component - The button to check against
* @returns A boolean that indicates if the button has a `custom_id` attached to it
@@ -114,10 +115,22 @@ export function isInteractionButton(component: APIButtonComponent): component is
return ![ButtonStyle.Link, ButtonStyle.Premium].includes(component.style);
}
// Modal
/**
* A type guard check for modals submit interactions
*
* @param interaction - The interaction to check against
* @returns A boolean that indicates if the interaction is a modal submission
*/
export function isModalSubmitInteraction(interaction: APIInteraction): interaction is APIModalSubmitInteraction {
return interaction.type === InteractionType.ModalSubmit;
}
// Message Components
/**
* A type-guard check for message component interactions
* A type guard check for message component interactions
*
* @param interaction - The interaction to check against
* @returns A boolean that indicates if the interaction is a message component
@@ -129,7 +142,7 @@ export function isMessageComponentInteraction(
}
/**
* A type-guard check for button message component interactions
* A type guard check for button message component interactions
*
* @param interaction - The message component interaction to check against
* @returns A boolean that indicates if the message component is a button
@@ -141,7 +154,7 @@ export function isMessageComponentButtonInteraction(
}
/**
* A type-guard check for select menu message component interactions
* A type guard check for select menu message component interactions
*
* @param interaction - The message component interaction to check against
* @returns A boolean that indicates if the message component is a select menu
@@ -161,7 +174,7 @@ export function isMessageComponentSelectMenuInteraction(
// Application Commands
/**
* A type-guard check for chat input application commands.
* A type guard check for chat input application commands.
*
* @param interaction - The interaction to check against
* @returns A boolean that indicates if the interaction is a chat input application command
@@ -173,7 +186,7 @@ export function isChatInputApplicationCommandInteraction(
}
/**
* A type-guard check for context menu application commands.
* A type guard check for context menu application commands.
*
* @param interaction - The interaction to check against
* @returns A boolean that indicates if the interaction is a context menu application command

View File

@@ -15,13 +15,14 @@ import type {
APIMessageComponentGuildInteraction,
APIMessageComponentInteraction,
APIMessageComponentSelectMenuInteraction,
APIModalSubmitInteraction,
} from '../payloads/v10/index';
import { ApplicationCommandType, ButtonStyle, ComponentType, InteractionType } from '../payloads/v10/index';
// Interactions
/**
* A type-guard check for DM interactions
* A type guard check for DM interactions
*
* @param interaction - The interaction to check against
* @returns A boolean that indicates if the interaction was received in a DM channel
@@ -31,7 +32,7 @@ export function isDMInteraction(interaction: APIInteraction): interaction is API
}
/**
* A type-guard check for guild interactions
* A type guard check for guild interactions
*
* @param interaction - The interaction to check against
* @returns A boolean that indicates if the interaction was received in a guild
@@ -43,7 +44,7 @@ export function isGuildInteraction(interaction: APIInteraction): interaction is
// ApplicationCommandInteractions
/**
* A type-guard check for DM application command interactions
* A type guard check for DM application command interactions
*
* @param interaction - The application command interaction to check against
* @returns A boolean that indicates if the application command interaction was received in a DM channel
@@ -55,7 +56,7 @@ export function isApplicationCommandDMInteraction(
}
/**
* A type-guard check for guild application command interactions
* A type guard check for guild application command interactions
*
* @param interaction - The interaction to check against
* @returns A boolean that indicates if the application command interaction was received in a guild
@@ -69,7 +70,7 @@ export function isApplicationCommandGuildInteraction(
// MessageComponentInteractions
/**
* A type-guard check for DM message component interactions
* A type guard check for DM message component interactions
*
* @param interaction - The message component interaction to check against
* @returns A boolean that indicates if the message component interaction was received in a DM channel
@@ -81,7 +82,7 @@ export function isMessageComponentDMInteraction(
}
/**
* A type-guard check for guild message component interactions
* A type guard check for guild message component interactions
*
* @param interaction - The interaction to check against
* @returns A boolean that indicates if the message component interaction was received in a guild
@@ -95,7 +96,7 @@ export function isMessageComponentGuildInteraction(
// Buttons
/**
* A type-guard check for buttons that have a `url` attached to them.
* A type guard check for buttons that have a `url` attached to them.
*
* @param component - The button to check against
* @returns A boolean that indicates if the button has a `url` attached to it
@@ -105,7 +106,7 @@ export function isLinkButton(component: APIButtonComponent): component is APIBut
}
/**
* A type-guard check for buttons that have a `custom_id` attached to them.
* A type guard check for buttons that have a `custom_id` attached to them.
*
* @param component - The button to check against
* @returns A boolean that indicates if the button has a `custom_id` attached to it
@@ -114,10 +115,22 @@ export function isInteractionButton(component: APIButtonComponent): component is
return ![ButtonStyle.Link, ButtonStyle.Premium].includes(component.style);
}
// Modal
/**
* A type guard check for modals submit interactions
*
* @param interaction - The interaction to check against
* @returns A boolean that indicates if the interaction is a modal submission
*/
export function isModalSubmitInteraction(interaction: APIInteraction): interaction is APIModalSubmitInteraction {
return interaction.type === InteractionType.ModalSubmit;
}
// Message Components
/**
* A type-guard check for message component interactions
* A type guard check for message component interactions
*
* @param interaction - The interaction to check against
* @returns A boolean that indicates if the interaction is a message component
@@ -129,7 +142,7 @@ export function isMessageComponentInteraction(
}
/**
* A type-guard check for button message component interactions
* A type guard check for button message component interactions
*
* @param interaction - The message component interaction to check against
* @returns A boolean that indicates if the message component is a button
@@ -141,7 +154,7 @@ export function isMessageComponentButtonInteraction(
}
/**
* A type-guard check for select menu message component interactions
* A type guard check for select menu message component interactions
*
* @param interaction - The message component interaction to check against
* @returns A boolean that indicates if the message component is a select menu
@@ -161,7 +174,7 @@ export function isMessageComponentSelectMenuInteraction(
// Application Commands
/**
* A type-guard check for chat input application commands.
* A type guard check for chat input application commands.
*
* @param interaction - The interaction to check against
* @returns A boolean that indicates if the interaction is a chat input application command
@@ -173,7 +186,7 @@ export function isChatInputApplicationCommandInteraction(
}
/**
* A type-guard check for context menu application commands.
* A type guard check for context menu application commands.
*
* @param interaction - The interaction to check against
* @returns A boolean that indicates if the interaction is a context menu application command

View File

@@ -15,13 +15,14 @@ import type {
APIMessageComponentGuildInteraction,
APIMessageComponentInteraction,
APIMessageComponentSelectMenuInteraction,
APIModalSubmitInteraction,
} from '../payloads/v9/index';
import { ApplicationCommandType, ButtonStyle, ComponentType, InteractionType } from '../payloads/v9/index';
// Interactions
/**
* A type-guard check for DM interactions
* A type guard check for DM interactions
*
* @param interaction - The interaction to check against
* @returns A boolean that indicates if the interaction was received in a DM channel
@@ -31,7 +32,7 @@ export function isDMInteraction(interaction: APIInteraction): interaction is API
}
/**
* A type-guard check for guild interactions
* A type guard check for guild interactions
*
* @param interaction - The interaction to check against
* @returns A boolean that indicates if the interaction was received in a guild
@@ -43,7 +44,7 @@ export function isGuildInteraction(interaction: APIInteraction): interaction is
// ApplicationCommandInteractions
/**
* A type-guard check for DM application command interactions
* A type guard check for DM application command interactions
*
* @param interaction - The application command interaction to check against
* @returns A boolean that indicates if the application command interaction was received in a DM channel
@@ -55,7 +56,7 @@ export function isApplicationCommandDMInteraction(
}
/**
* A type-guard check for guild application command interactions
* A type guard check for guild application command interactions
*
* @param interaction - The interaction to check against
* @returns A boolean that indicates if the application command interaction was received in a guild
@@ -69,7 +70,7 @@ export function isApplicationCommandGuildInteraction(
// MessageComponentInteractions
/**
* A type-guard check for DM message component interactions
* A type guard check for DM message component interactions
*
* @param interaction - The message component interaction to check against
* @returns A boolean that indicates if the message component interaction was received in a DM channel
@@ -81,7 +82,7 @@ export function isMessageComponentDMInteraction(
}
/**
* A type-guard check for guild message component interactions
* A type guard check for guild message component interactions
*
* @param interaction - The interaction to check against
* @returns A boolean that indicates if the message component interaction was received in a guild
@@ -95,7 +96,7 @@ export function isMessageComponentGuildInteraction(
// Buttons
/**
* A type-guard check for buttons that have a `url` attached to them.
* A type guard check for buttons that have a `url` attached to them.
*
* @param component - The button to check against
* @returns A boolean that indicates if the button has a `url` attached to it
@@ -105,7 +106,7 @@ export function isLinkButton(component: APIButtonComponent): component is APIBut
}
/**
* A type-guard check for buttons that have a `custom_id` attached to them.
* A type guard check for buttons that have a `custom_id` attached to them.
*
* @param component - The button to check against
* @returns A boolean that indicates if the button has a `custom_id` attached to it
@@ -114,10 +115,22 @@ export function isInteractionButton(component: APIButtonComponent): component is
return ![ButtonStyle.Link, ButtonStyle.Premium].includes(component.style);
}
// Modal
/**
* A type guard check for modals submit interactions
*
* @param interaction - The interaction to check against
* @returns A boolean that indicates if the interaction is a modal submission
*/
export function isModalSubmitInteraction(interaction: APIInteraction): interaction is APIModalSubmitInteraction {
return interaction.type === InteractionType.ModalSubmit;
}
// Message Components
/**
* A type-guard check for message component interactions
* A type guard check for message component interactions
*
* @param interaction - The interaction to check against
* @returns A boolean that indicates if the interaction is a message component
@@ -129,7 +142,7 @@ export function isMessageComponentInteraction(
}
/**
* A type-guard check for button message component interactions
* A type guard check for button message component interactions
*
* @param interaction - The message component interaction to check against
* @returns A boolean that indicates if the message component is a button
@@ -141,7 +154,7 @@ export function isMessageComponentButtonInteraction(
}
/**
* A type-guard check for select menu message component interactions
* A type guard check for select menu message component interactions
*
* @param interaction - The message component interaction to check against
* @returns A boolean that indicates if the message component is a select menu
@@ -161,7 +174,7 @@ export function isMessageComponentSelectMenuInteraction(
// Application Commands
/**
* A type-guard check for chat input application commands.
* A type guard check for chat input application commands.
*
* @param interaction - The interaction to check against
* @returns A boolean that indicates if the interaction is a chat input application command
@@ -173,7 +186,7 @@ export function isChatInputApplicationCommandInteraction(
}
/**
* A type-guard check for context menu application commands.
* A type guard check for context menu application commands.
*
* @param interaction - The interaction to check against
* @returns A boolean that indicates if the interaction is a context menu application command