You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Typescript: Option<> does not include null in generated types #244
The issue is that unless we are using #[serde(skip_serializing_if = "Option::is_none")] attribute, then if my_name has value None it gets serialized as null in JSON:
{
"my_name": null,
"my_age": 21
}
However, the generated Typescript definition does not reflect that my_name can hold a null value:
/* Generated by typeshare 1.13.2*/exportinterfaceMyStruct{my_name?: string;my_age: number;}
This leads to potential unchecked nulls in our typescript part of the project.
Proposed solution
The best solution would be to adapt how Option<> types are treated based on the presence or absence of serde attribute.
If this is not possible, then null could simply be added to type definition of optional properties, enforcing safer typechecking.
However, that might be a breaking change to projects already relying on serde attribute so perhaps there should be a command line option to opt-in to this behavior.
Related issues
There is a similar issue about unit type: #43 which has been attempted to be fixed by #82 however reverted due to #96 and now is hanging in a draft pr #98.
Version
typeshare-cli version 1.13.2
typeshare crate version 1.0.4
Reacted by Henrik Nygren, Martinez, __dil__ and Parsa Shamaeezadeh
Activity
maiia-kuzmishyna commentedon Jun 19, 2025
Additionally, typeshare incorrectly maps nested
Option<T>, for example in arrays, e.g.gets mapped to
This completely hides the information that an individual element of array can be
null.