-
Notifications
You must be signed in to change notification settings - Fork 138
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
Optional generic fields break with #[ts(optional)] if they are second generic or don't have implicit TS trait.
Please look at examples, they show it clearly.
To Reproduce
// Will break:
#[derive(Serialize, TS)]
#[ts(export, export_to = "optional_field/")]
struct GenericOptionalStruct<T1, T2>
{
#[ts(optional)] // <- error is happening here
a: Option<T2>,
#[ts(optional = nullable)]
b: Option<T1>,
c: Option<T1>,
}
// Works:
#[derive(Serialize, TS)]
#[ts(export, export_to = "optional_field/")]
struct GenericOptionalStruct<T1, T2>
{
#[ts(optional = nullable)] // <- set to nullable
a: Option<T2>,
#[ts(optional = nullable)]
b: Option<T1>,
c: Option<T1>,
}
// Works:
#[derive(Serialize, TS)]
#[ts(export, export_to = "optional_field/")]
struct GenericOptionalStruct<T1, T2>
where // <- added TS requirements
T1: TS,
T2: TS,
{
#[ts(optional)]
a: Option<T2>,
#[ts(optional = nullable)]
b: Option<T1>,
c: Option<T1>,
}
// Works:
#[derive(Serialize, TS)]
#[ts(export, export_to = "optional_field/")]
struct GenericOptionalStruct<T> // <- removed T2
where
T: TS,
{
#[ts(optional)]
a: Option<T>,
#[ts(optional = nullable)]
b: Option<T>,
c: Option<T>,
}Expected behavior
For the first example to work
Version
11.1.0
Additional context
I haven't found out why exactly the issue is happening. may add later.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working