fix(utils): support array and dynamic types for .json fields in DML - #16236
Conversation
🦋 Changeset detectedLatest commit: c169221 The changes in this PR will be included in the next version bump. This PR includes changesets to release 79 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Thanks for the contribution! Initial automated review looks good. Team member PR adding a type parameter to JSONProperty and the json() builder method so callers can specify array or other JSON-serializable types. The change is purely type-level with no runtime impact. Tests use expectTypeOf to verify the default resolves to Record<string, unknown> and that custom types (e.g. arrays) thread through correctly. NoInfer<T> is used correctly to prevent contextual widening. Changeset included at patch level. No security, performance, or correctness concerns. Triggered by: manual workflow dispatch |
The
.jsonfield maps to ajsonbcolumn, which can hold any JSON serializable value, such as arrays.With the current approach, we always typed
jsonfields asRecord<string, unknown>. So, if you were to set an array value it would show a type error, even though it is supported by the backend / database.This PR allows passing a type argument to
.json()to specify the expected type of the field, which maps into types in the module's service and the data model itself.For example:
Base
jsonfields retain theirRecord<string, unknown>type.Closes DX-2824