obscure getKey type error on collection options
If I have a property in my schema that I have chosen as id for queryCollectionOptions and it is optional
then I see a long type error on the entire config object (inside queryCollectionOptions)
I understand the error, but why isn't the error related only to the getKey property instead of the entire config?)
2 Replies
conscious-sapphire•2mo ago
Some of the type errors can get quite complex, we need to look how to improve these.
In this case I think if you configure the Zod schema to have a default id it will work.
Zod schemas have input and output types, the output type is the one used for the collection type, and the input type is used for the insert/update/delete methods. It is expected that the id is not optional in the output type as it can't be optional on the collection.
If you want to have server driven ids that are allocated when persisting to your api, then you still need to provide a local temporary id for the row. But in your case you have a uuid, and so can safely allocate it on the client. I also notice you are not passing the Zod schema to the collection just inferi f its type, you can pass it to the collection so that it uses it for validation:
unwilling-turquoiseOP•5w ago
Thank u @samwillis
When I use your code example I still see the error)
Here's the code that I just pasted into mine for testing:
In order not to see the error, I have to remove the schema property
I realized that I can EITHER use a type for queryCollectionOptions OR use the schema property without specifying the type at the beginning.