`HashMap` value as `any` type
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?
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?
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.