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
Json.serializeExn and Json.deserializeUnsafe were introduced to allow string serialization of records that contain option values.
E.g.
let user = {
name: "test",
age: None
}
would compile to { name: "test", age: undefined} — a JS object that's not stringifiable due to the undefined value (which is not part of the JSON spec).
This was particularly an issue in Next, when using specific features like SSR to inject initial props (see #4443 for the full discussion).
Now with our new @optional feature (#5423) this is not needed anymore, since I would just declare a prop type as followed:
typeuser= {
name: string,
@optionalage: int
}
Later on I'd just omit the age and be good to go. No undefined values in the output:
letuser= {name: "patrick"}
// Equal to `{name: "patrick"}` in JS
My suggestion is to add a deprecation notice and point to the new docs of the @optional feature instead. Any opinions?
The text was updated successfully, but these errors were encountered:
After some discussions with @cristianoc, it's probably better to wait a little longer until we move on with this. Will still keep it around for later reference.
Json.serializeExn
andJson.deserializeUnsafe
were introduced to allow string serialization of records that containoption
values.E.g.
would compile to
{ name: "test", age: undefined}
— a JS object that's not stringifiable due to theundefined
value (which is not part of the JSON spec).This was particularly an issue in Next, when using specific features like SSR to inject initial props (see #4443 for the full discussion).
Now with our new
@optional
feature (#5423) this is not needed anymore, since I would just declare a prop type as followed:Later on I'd just omit the
age
and be good to go. Noundefined
values in the output:My suggestion is to add a deprecation notice and point to the new docs of the
@optional
feature instead. Any opinions?The text was updated successfully, but these errors were encountered: