Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change JSONValue to allow ReadonlyArray #10

Open
garybernhardt opened this issue Mar 15, 2022 · 0 comments
Open

Change JSONValue to allow ReadonlyArray #10

garybernhardt opened this issue Mar 15, 2022 · 0 comments

Comments

@garybernhardt
Copy link

Background:

When possible, it's preferable to accept read-only arrays as arguments. That allows upstream callers to pass read-only arrays or regular arrays in. But passing a read-only array in place of a regular array is disallowed. (Because the function is effectively saying "I might mutate that array", which would break the "read-only-ness" of the ReadonlyArray<T>.)

My problem:

  • We have some JSON columns.
  • Some of the app's functions want to write values into those columns, and the values contain some read-only arrays.
  • It's not possible to write these values (or any value containing a ReadonlyArray) into a postgres-schema-ts JSONValue column. The JSONValue type only allows Array<T>.

My proposed solution:

Change JSONArray to:

export type JSONArray = ReadonlyArray<JSONValue>

I tried to do this myself, but failed to run the tests, and this is definitely a change where I want to see the tests run. I installed docker-compose (v2.3.3, which is current according to homebrew). Still, the tests fail like this:

$ npm run test

> [email protected] test /Users/grb/Downloads/src/postgres-schema-ts
> docker-compose up -d && jest --runInBand --forceExit

(root) Additional property musicbrainz is not allowed

So no PR from me. But looking at the code, this feels like a very quick change.

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

No branches or pull requests

1 participant