You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The code above generates TypeScript errors for the omit() calls: The type 'readonly ["id", "createdAt", "updatedAt"]' is 'readonly' and cannot be assigned to the mutable type 'ObjectKeys<...>'..
Why even pass a readonly array to omit()?
I have a couple of different entities in my data model, all share the same common properties defined in entityMixin. I also have CRUD endpoints for all of these entities that work pretty much the same: The create mutations receive a property bag, generate an ID for the new entity, and return the full object.
Because all create and update mutations omit the same properties from their input type, I declared that key array as a reusable variable in omitProps.create. By declaring that variable as const, it's type becomes readonly ["id", "createdAt", "updatedAt"]. I can't remove the as const, because then typeof omitProps.create would become string[], and the specific property name literals would get lost.
I'm only using omit() at the moment, so for me it would be sufficient to fix this one method for now. If you want me to, I can go over the remaining API and check for other places that should also be changed (for API consistency).
I can open a PR if you want, just wanted to check first if you're even interested in this change.
The text was updated successfully, but these errors were encountered:
Thanks for bringing this up. I will update the types of omit and pick and add our MaybeReadonly util type to support both cases. Feel free to create more issues if you encounter problems or have ideas on how we can further improve the library.
I will release a new version in the next days. If you don't want to wait, you can build the library with the changes yourself. Contact me if you want to do that and need help.
Hey! Great package, I really enjoy using it, and I like the elegant yet expressive API! :)
I'd like to request a minor API change regarding the
omit()
method. Please change the signature toomit(schema: TSchema, keys: Readonly<TKeys>)
.Example use case
I'm using valibot for tRPC input validation. Here is a simplified example of my backend setup:
The code above generates TypeScript errors for the
omit()
calls:The type 'readonly ["id", "createdAt", "updatedAt"]' is 'readonly' and cannot be assigned to the mutable type 'ObjectKeys<...>'.
.Why even pass a
readonly
array toomit()
?I have a couple of different entities in my data model, all share the same common properties defined in
entityMixin
. I also have CRUD endpoints for all of these entities that work pretty much the same: The create mutations receive a property bag, generate an ID for the new entity, and return the full object.Because all create and update mutations omit the same properties from their input type, I declared that key array as a reusable variable in
omitProps.create
. By declaring that variableas const
, it's type becomesreadonly ["id", "createdAt", "updatedAt"]
. I can't remove theas const
, because thentypeof omitProps.create
would becomestring[]
, and the specific property name literals would get lost.I'm only using
omit()
at the moment, so for me it would be sufficient to fix this one method for now. If you want me to, I can go over the remaining API and check for other places that should also be changed (for API consistency).I can open a PR if you want, just wanted to check first if you're even interested in this change.
The text was updated successfully, but these errors were encountered: