Skip to content

Commit

Permalink
Fix TS export by defining new struct for each generic type used (#6995)
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles authored Dec 5, 2024
1 parent 9a2061f commit 4b0c39e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions backend/libraries/types/src/bots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub enum SlashCommandParamType {
pub struct StringParam {
pub min_length: u16,
pub max_length: u16,
#[ts(as = "SlashCommandOptionChoiceString")]
pub choices: Vec<SlashCommandOptionChoice<String>>,
}

Expand All @@ -45,6 +46,7 @@ pub struct StringParam {
pub struct NumberParam {
pub min_length: u16,
pub max_length: u16,
#[ts(as = "SlashCommandOptionChoiceU16")]
pub choices: Vec<SlashCommandOptionChoice<u16>>,
}

Expand Down Expand Up @@ -85,3 +87,17 @@ pub struct BotMatch {
pub banner_id: Option<u128>,
pub commands: Vec<SlashCommandSchema>,
}

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

0 comments on commit 4b0c39e

Please sign in to comment.