`ts(optional)` should be working on any which has `skip_serializing_if`
Closed this issue · 1 comments
xiao-e-yun commented
Describe the bug
ts(optional)
can't support skip_serializing_if attr
To Reproduce
- Write this code
#[ts(export)]
#[derive(TS , Serialize)]
pub struct A{
#[ts(optional)]
#[serde(skip_serializing_if = "<[_]>::is_empty")]
pub arrays: Vec<String>,
}
- Throw error:
optional
can only be used on an Option type
Expected behavior
return type
export type A = { arrays?: Array<string>, };
NyxCode commented
On 8.1.0, you can use
#[ts(as = "Option<Vec<String>>", optional)]
my_vec: Vec<String>
On the latest master (and soon in 9.0.0), you can then do
#[ts(as = "Option<_>", optional)]
my_vec: Vec<String>
It is by design that the TS types we generate match the type in Rust. This has been discussed at length before, see #175.