Open hornta opened 1 year ago
Hadn't heard of that proposal yet, that looks great! Good work by the Igalia folks.
This is in Stage 3 right now, and not yet available in Browsers (I checked Chrome), so i'd like to hold off on including it in SuperJSON core right now.
If you want to support PlainDate in your project right now, you can use SuperJSON.registerCustom
: https://github.com/blitz-js/superjson#decimaljs--prismadecimal
I do this
import { Temporal } from '@js-temporal/polyfill';
import superjson from 'superjson';
superjson.registerCustom<Temporal.PlainDate, string>(
{
isApplicable: (v): v is Temporal.PlainDate =>
v instanceof Temporal.PlainDate,
serialize: (v) => v.toJSON(),
deserialize: (v) => Temporal.PlainDate.from(v),
},
'Temporal.PlainDate',
);
superjson.registerCustom<Temporal.Instant, string>(
{
isApplicable: (v): v is Temporal.Instant => v instanceof Temporal.Instant,
serialize: (v) => v.toJSON(),
deserialize: (v) => Temporal.Instant.from(v),
},
'Temporal.Instant',
);
Like PlainDate and more
https://tc39.es/proposal-temporal/docs/plaindate.html