Description
I'm encountering a TypeScript type error when using the create method on a model that has a required relationship.
The issue occurs when I first provide the foreign key for the relation (e.g., authorId) and then use the spread operator (...) to pass in the remaining data for the creation. Even though the relation is satisfied by the foreign key, the type system flags an error because the spread object's type includes the optional relation field (e.g., author), which it believes is incompatible.
Reproduction
I have created a minimal repository to demonstrate the issue:
https://github.com/DomZem/zenstack-not-null
The relevant code is in the post.builder.ts file, specifically within the build method.
Example usage of that class is in seed.ts
Expected Behavior
The create method's types should correctly infer that the relation is satisfied when a foreign key is provided. It should not produce a type error when other optional data is spread, even if that data's type includes the optional relation field.
Environment
- ZenStack version: 3.5.6
- Database type: Postgresql
- Node.js/Bun version: 20.19.6
- Package manager: pnpm
Description
I'm encountering a TypeScript type error when using the create method on a model that has a required relationship.
The issue occurs when I first provide the foreign key for the relation (e.g., authorId) and then use the spread operator (...) to pass in the remaining data for the creation. Even though the relation is satisfied by the foreign key, the type system flags an error because the spread object's type includes the optional relation field (e.g., author), which it believes is incompatible.
Reproduction
I have created a minimal repository to demonstrate the issue:
https://github.com/DomZem/zenstack-not-null
The relevant code is in the
post.builder.tsfile, specifically within the build method.Example usage of that class is in
seed.tsExpected Behavior
The create method's types should correctly infer that the relation is satisfied when a foreign key is provided. It should not produce a type error when other optional data is spread, even if that data's type includes the optional relation field.
Environment