X
Xataโ€ข11mo ago
maxfi

`toSerializable()` makes column types {orginal_type} | undefined

No description
12 Replies
maxfi
maxfiOPโ€ข11mo ago
Note that the description type is String and not null. After calling toSerializable() on the record the type is string | undefined.
maxfi
maxfiOPโ€ข11mo ago
My current workaround. I'm not really a fan of using typescript's as. Hope there is a better solution. ๐Ÿ™
No description
maxfi
maxfiOPโ€ข11mo ago
No description
maxfi
maxfiOPโ€ข11mo ago
Also, ideally I'd like to be able to avoid the map to fix the types (including the productId being string | null | undefined
No description
kostas
kostasโ€ข11mo ago
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?
maxfi
maxfiOPโ€ข11mo ago
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.
kostas
kostasโ€ข11mo ago
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.
maxfi
maxfiOPโ€ข11mo ago
Thanks @kostas. Yup, I'll try to get that done tomorrow. ๐Ÿ‘
maxfi
maxfiOPโ€ข10mo ago
Hi @kostas. I've created the issue https://github.com/xataio/client-ts/issues/1410. Thanks. ๐Ÿ™
GitHub
Issues ยท xataio/client-ts
Xata.io SDK for TypeScript and JavaScript. Contribute to xataio/client-ts development by creating an account on GitHub.
kostas
kostasโ€ข10mo ago
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.
maxfi
maxfiOPโ€ข10mo ago
Awesome! Thanks @kostas! ๐Ÿ™
Bill.IHCha
Bill.IHChaโ€ข2mo ago
is this ever going to be fixed?
Want results from more Discord servers?
Add your server