Skip to content

Conversation

@adriand
Copy link
Contributor

@adriand adriand commented Apr 3, 2025

This pull request adds support for json and jsonb fields, converting them to Record<string, any> in the Typescript types.

This might be worth a discussion, since Typescript conventions would dictate that a more appropriate type is Record<string, unknown>, given that any is seen as a code smell. However, making it Record<string, unknown> would have the effect of forcing you to override the library's type conversion, by either specifying Record<string, any> or by writing a more comprehensive type, which defeats the purpose of automatic conversion.

A stronger alternative would be something like JSONObject:

type JSONValue = 
  | string
  | number
  | boolean
  | null
  | JSONValue[]
  | { [key: string]: JSONValue };

type JSONObject = { [key: string]: JSONValue };

But that seems like a fairly large departure from the current approach of fairly straightforward type conversion.

@ElMassimo
Copy link
Owner

Hi Adrian!

Typescript conventions would dictate that a more appropriate type is Record<string, unknown>

Agreed, but given the library allows you to specify a more strict type (or even, create another serializer for that JSONB structure), I'm fully on board with the option you chose.

Thanks!

@ElMassimo ElMassimo merged commit 34e747f into ElMassimo:main Apr 8, 2025
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants