flightcontrolhq / superjson

Safely serialize JavaScript expressions to a superset of JSON, which includes Dates, BigInts, and more.
https://www.flightcontrol.dev?ref=superjson
MIT License
4.02k stars 87 forks source link

Error when parsing data with Buffer #210

Closed ymc9 closed 1 year ago

ymc9 commented 1 year ago

Hi there,

is Buffer type supported? It seems I can stringify but can't parse it back:

const superjson = require('superjson');
superjson.stringify({d: Buffer.from('hello')});

Uncaught Error: Trying to deserialize unknown typed array

ymc9 commented 1 year ago

Oh, I see that I need to register a custom type. Closing now 😄

Skn0tt commented 1 year ago

Yup, custom type needed. It's not universally available on all platforms (only Node.js), so we can't make it a default type 🤷