Skip to content

Fix type inference in ZodMiniType check method#4568

Merged
colinhacks merged 2 commits intocolinhacks:mainfrom
rphlmr:fix/4326-v4-mini-object-check-value
May 30, 2025
Merged

Fix type inference in ZodMiniType check method#4568
colinhacks merged 2 commits intocolinhacks:mainfrom
rphlmr:fix/4326-v4-mini-object-check-value

Conversation

@rphlmr
Copy link
Copy Markdown
Contributor

@rphlmr rphlmr commented May 30, 2025

Closes: #4326

.check() on a z.object now correctly infers value.

Before:

const Thing = z.object({
  name: z.string(),
  age: z.number()
}).check(({ value, issues }) => {
  value // => any
});

After:

const Thing = z.object({
  name: z.string(),
  age: z.number()
}).check(({ value, issues }) => {
  value // => { name: string; age: number }
});

@colinhacks
Copy link
Copy Markdown
Owner

Nice catch, thanks!!

@colinhacks colinhacks merged commit 508e306 into colinhacks:main May 30, 2025
3 of 4 checks passed
colinhacks added a commit that referenced this pull request May 31, 2025
* Fix type inference in ZodMiniType check method and add tests for z.object().check()

* Fix more references to _zod.output

---------

Co-authored-by: Colin McDonnell <[email protected]>
timorthi pushed a commit to timorthi/zod that referenced this pull request Jun 3, 2025
* Fix type inference in ZodMiniType check method and add tests for z.object().check()

* Fix more references to _zod.output

---------

Co-authored-by: Colin McDonnell <[email protected]>
timorthi pushed a commit to timorthi/zod that referenced this pull request Jun 3, 2025
* Fix type inference in ZodMiniType check method and add tests for z.object().check()

* Fix more references to _zod.output

---------

Co-authored-by: Colin McDonnell <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v4: z.object().check() types the value property as any

2 participants