Typings
Learn about type safety in Honocord.
Honocord is built with TypeScript and provides deep type-safety for your Discord interactions. Since it’s built on top of Hono, it leverages Hono’s powerful context system while adding Discord-specific enhancements.
Base Interaction Context
The core of Honocord’s type safety is the BaseInteractionContext. This type extends Hono’s context and provides access to your environment bindings (like Cloudflare Workers environment variables) and custom Hono variables.
Defining your Environment
To get full type safety, you should first define your environment’s bindings and variables.
Applying Types to Handlers
To get full type safety within your handlers, pass your custom context type as a generic parameter when instantiating them. See the Handlers guide for more details on creates handlers.
Middleware Type Safety
When writing middleware for Honocord, use the MiddlewareFunction type to ensure the context is correctly typed.
Built-in Interaction Types
Honocord provides typed interactions for all supported Discord interaction types. These inherit your custom context:
ChatInputCommandInteraction<Context>: For slash commands.AutocompleteInteraction<Context>: For autocomplete options.ButtonInteraction<Context>: For button components.StringSelectInteraction<Context>: For string select menus.UserSelectInteraction<Context>,RoleSelectInteraction<Context>, etc.ModalInteraction<Context>: For modal submissions.UserContextInteraction<Context>&MessageContextInteraction<Context>: For context menu commands.