Description and expected behavior
A clear and concise description of what the bug is and what's the expected behavior.
The TypeScript definition for inferring a Zod schema type from a Zen schema is incorrect for scalar arrays like String[]. The array-ness is lost, and the Zod types report z.ZodString instead of z.ZodArray<z.ZodString>.
This seems to be due to a missing ZodArrayIf in the scalar branch here:
|
export type GetModelFieldsShape<Schema extends SchemaDef, Model extends GetModels<Schema>> = { |
|
// scalar fields |
|
[Field in GetModelFields<Schema, Model> as FieldIsRelation<Schema, Model, Field> extends true |
|
? never |
|
: Field]: ZodOptionalAndNullableIf< |
|
MapModelFieldToZod<Schema, Model, Field>, |
|
ModelFieldIsOptional<Schema, Model, Field> |
|
>; |
This means types do not match runtime, where the Zod schema is actually correct, because applyCardinality is used properly in makeScalarFieldSchema here:
|
return this.applyCardinality(base, fieldDef); |
Screenshots
If applicable, add screenshots to help explain your problem.
Environment (please complete the following information):
- ZenStack version: 3.4.6 with
@zenstackhq/zod@3.4.6
- Database type: any
- Node.js/Bun version: any
- Package manager: any
Additional context
Add any other context about the problem here.
Description and expected behavior
A clear and concise description of what the bug is and what's the expected behavior.
The TypeScript definition for inferring a Zod schema type from a Zen schema is incorrect for scalar arrays like
String[]. The array-ness is lost, and the Zod types reportz.ZodStringinstead ofz.ZodArray<z.ZodString>.This seems to be due to a missing
ZodArrayIfin the scalar branch here:zenstack/packages/zod/src/types.ts
Lines 22 to 29 in 00768de
This means types do not match runtime, where the Zod schema is actually correct, because
applyCardinalityis used properly inmakeScalarFieldSchemahere:zenstack/packages/zod/src/factory.ts
Line 174 in 00768de
Screenshots
If applicable, add screenshots to help explain your problem.
Environment (please complete the following information):
@zenstackhq/zod@3.4.6Additional context
Add any other context about the problem here.