Skip to content

Commit 672e590

Browse files
committed
Array-level errors weren't typed correctly when changing the cardinality of an array schema field.
1 parent fd5a51c commit 672e590

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ Headlines: Added, Changed, Deprecated, Removed, Fixed, Security
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
10+
### Fixed
11+
12+
- Array-level errors weren't typed correctly when changing the cardinality of an array field in the schema (for example with `nonempty`).
13+
814
## [1.5.2] - 2023-08-15
915

1016
### Fixed

src/lib/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,13 @@ type SuperStructArray<T extends AnyZodObject, Data, ArrayData = unknown> = {
6262
? SuperStructArray<IntersectUnion<UnwrappedEntity<T>>, Data, ArrayData>
6363
: UnwrappedRawShape<T, Property> extends AnyZodObject
6464
? SuperStructArray<UnwrappedRawShape<T, Property>, Data, ArrayData>
65-
: UnwrappedRawShape<T, Property> extends ZodArray<infer A>
65+
: UnwrappedRawShape<T, Property> extends ZodArray<
66+
infer A,
67+
// Need to infer Cardinality for extend to work correctly, even though it's unused.
68+
// (nonempty changes the cardinality of arrays in the schema)
69+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
70+
infer Cardinality
71+
>
6672
? ArrayData &
6773
Record<
6874
number,

0 commit comments

Comments
 (0)