dynamodb-onetable: Strict typing on create() doesn't account for generated fields
Describe the bug
This change: https://github.com/sensedeep/dynamodb-onetable/pull/339 changed the typedef for Model.create() to enforce required model properties during create. This makes sense, except if you have a required property that’s also generated.
For example, we have a property like this
consumerId: { type: String, generate: true, required: true },
The new type schema requires I manually input consumerId
and gives an error Property 'consumerId' is optional in type 'Partial<Consumer>' but required in type '{ consumerId: ConsumerId; ...
To Reproduce
I’m not entirely sure how to give you a repro for a type issue. I can try if this isn’t clear though.
Expected behavior
Generated fields should be marked required in the Model type, but not in the input to Model.create
Screenshots If applicable, add screenshots to help explain your problem.
Environment (please complete the following information):
- OS: Mac OS
- Node Version: 14.18
- OneTable Version: 2.3.8
- TypeScript Version: 4.6.3
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 17 (14 by maintainers)
To do that, just define them in your model. TS definitions are auto-generated from your schema, so if you want them defined, you need to include them in your model.