Skip to content

HashMap value as any type #62

Open

Description

@paydii

Hey, thanks for this. It's been really useful.

I'm trying to convert a dynamic metadata field that will be unkown of type as the value, but the key will always be a string.

#[derive(Serialize, Deserialize, Debug)]
#[tsync]
pub struct Transaction {
    pub id: i32,
    pub amount: i32,
    pub formatted_amount: String,
    pub transaction_type: String,
    pub description: String,
    pub balance_after: i32,
    pub reference: Option<TransactionReference>,
    pub metadata: Option<HashMap<String, String>>,
    pub created_at: String,
    pub credit: bool,
    pub debit: bool,
}

I found this issue but not sure if it explains my case. What I tried are change the type to Option<HashMap<String, Value>> and pub metadata: Option<Value>, to no succeed. They were generated as metadata?: Value; which is unkown type.

Is this possible at all?

Activity

  1. changed the title [-]HasMap value as any type[/-] [+]`HashMap` value as any type[/+] on Aug 28, 2025
  2. changed the title [-]`HashMap` value as any type[/-] [+]`HashMap` value as `any` type[/+] on Aug 28, 2025
  3. AnthonyMichaelTDM commented on Oct 30, 2025

    @AnthonyMichaelTDM
    Collaborator

    this might be possible if/when #34 is implemented, but until then would defining Value as an alias to any in your typescript do the trick?

  4. Wulf commented on Dec 23, 2025

    @Wulf
    Owner

    My suggestion is to introduce a Rust alias for this

    type SomeAlias = String
    
    #[tsync]
    pub struct Example {
        pub meta: Option<HashMap<String, SomeAlias>>,
    }

    and in your typescript, add the following (in a global types file)

    type SomeAlias = any

    That way you don't have to use Value in your HashMap on the Rust side.

    You can also use a custom type when #73 is merged in, but (personally) I'd opt for the alias here so future refactors maintain integrity without having to manually update the #[tsync(ts_type='...') string in the attribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions