Aleph-Alpha/ts-rs

`ts(optional)` should be working on any which has `skip_serializing_if`

Closed this issue · 1 comments

Describe the bug
ts(optional) can't support skip_serializing_if attr

To Reproduce

  1. Write this code
#[ts(export)]
#[derive(TS , Serialize)]
pub struct A{
    #[ts(optional)]
    #[serde(skip_serializing_if = "<[_]>::is_empty")]
    pub arrays: Vec<String>,
}
  1. Throw error: optional can only be used on an Option type

Expected behavior
return type

export type A = { arrays?: Array<string>, };

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.