blitz-js / superjson

Safely serialize JavaScript expressions to a superset of JSON, which includes Dates, BigInts, and more.
MIT License
3.88k stars 83 forks source link

Trying to use it with ofetch #278

Closed digoburigo closed 7 months ago

digoburigo commented 7 months ago

I'm trying to use superjson with ofetch Is there something specific to make superjson work with this fetch alternative?

const ofetchOptions: FetchOptions = {
  baseURL: 'https://jsonplaceholder.typicode.com',
  parseResponse: superjson.parse, // this don't work
};
const api = ofetch.create(ofetchOptions);

Already open an issue in their repo.

Skn0tt commented 7 months ago

Hey @digoburigo! You're holding it wrong. The typicode API doesn't return SuperJSON, but normal JSON. That's why SuperJSON will return undefined.

What are you trying to achieve? If the goal is to parse the incoming JSON, use parseResponse: JSON.parse instead.

digoburigo commented 7 months ago

Yes. I tried doing something that it's not possible. That is returning a superjson from a normal json response. That is not the purpose of this library. Sorry for the confusion.