From 4b0c39eca54b28b3a544e61327c9cab55bd00fcb Mon Sep 17 00:00:00 2001 From: Hamish Peebles Date: Thu, 5 Dec 2024 17:33:40 +0000 Subject: [PATCH] Fix TS export by defining new struct for each generic type used (#6995) --- backend/libraries/types/src/bots.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/backend/libraries/types/src/bots.rs b/backend/libraries/types/src/bots.rs index 2f4aace611..8101ae4b8f 100644 --- a/backend/libraries/types/src/bots.rs +++ b/backend/libraries/types/src/bots.rs @@ -37,6 +37,7 @@ pub enum SlashCommandParamType { pub struct StringParam { pub min_length: u16, pub max_length: u16, + #[ts(as = "SlashCommandOptionChoiceString")] pub choices: Vec>, } @@ -45,6 +46,7 @@ pub struct StringParam { pub struct NumberParam { pub min_length: u16, pub max_length: u16, + #[ts(as = "SlashCommandOptionChoiceU16")] pub choices: Vec>, } @@ -85,3 +87,17 @@ pub struct BotMatch { pub banner_id: Option, pub commands: Vec, } + +macro_rules! slash_command_option_choice { + ($name:ident, $value_type:ty) => { + #[ts_export] + #[derive(CandidType, Serialize, Deserialize, Clone, Debug)] + struct $name { + pub name: String, + pub value: $value_type, + } + }; +} + +slash_command_option_choice!(SlashCommandOptionChoiceString, String); +slash_command_option_choice!(SlashCommandOptionChoiceU16, u16);