12 Replies
Note that the
description
type is String
and not null
. After calling toSerializable()
on the record the type is string | undefined
.My current workaround. I'm not really a fan of using typescript's
as
. Hope there is a better solution. ๐Also, ideally I'd like to be able to avoid the
map
to fix the types (including the productId
being string | null | undefined
Hello, the purpose of the
toSerializable
method is to convert content to plain JSON so it can be passed to the client, where the JSONData
helper function restores the original types.
You can find a reference here: https://xata.io/docs/sdk/typescript/overview#serializing-xata-data-structures
Have you tried JSONData, or is there some other reason why you're needing to fix up the types this way?Hi @kostas. Thanks for getting back to me. ๐ Yeah, I need to serialize the data to be able to return it from a next.js api route that gets used on the client with
react-query
. I need to serialize it remove the xata functions, otherwise next.js throws errors.
I've tried the JSONData
helper but all the columns end up being optional. Ie, null | undefined
is being added to the type of each column.I think this might call for an enhancement for the
JSONData
helper to consider the column constraints (such as notNull) when adding back the types. Would you mind opening an issue in the open source client-ts repo for our SDK team to review? https://github.com/xataio/client-ts/issues I can do it on your behalf, let me know!GitHub
Issues ยท xataio/client-ts
Xata.io SDK for TypeScript and JavaScript. Contribute to xataio/client-ts development by creating an account on GitHub.
Thanks @kostas. Yup, I'll try to get that done tomorrow. ๐
GitHub
Issues ยท xataio/client-ts
Xata.io SDK for TypeScript and JavaScript. Contribute to xataio/client-ts development by creating an account on GitHub.
Great, I'll bring it to the dev team's attention. Thanks for the clear description! We'll let you know if anything else is needed.
Awesome! Thanks @kostas! ๐
is this ever going to be fixed?