Skip to content

fix: remove redundant Required<> from input and output type definitions #5033

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

yz89122
Copy link
Contributor

@yz89122 yz89122 commented Aug 3, 2025

Summary

  • Removes redundant Required<> utility type from both input and output type definitions
  • Fixes TS2615 circular reference errors in TypeScript 5.9+
  • No functional changes - the type behavior remains identical

Problem

The Required<> utility type in both type definitions was redundant:

export type input<T> = T extends { _zod: { input: any } } ? Required<T["_zod"]>["input"] : unknown;
export type output<T> = T extends { _zod: { output: any } } ? Required<T["_zod"]>["output"] : unknown;

The type guards T extends { _zod: { input: any } } and T extends { _zod: { output: any } } already ensure that input and output are required properties. If either were optional, the conditions would fail and return unknown.

This redundant Required<> caused TS2615 errors in TypeScript 5.9+ when using recursive schemas because it introduced unnecessary mapped types in circular reference chains.

Solution

Simplified both type definitions to:

export type input<T> = T extends { _zod: { input: any } } ? T["_zod"]["input"] : unknown;
export type output<T> = T extends { _zod: { output: any } } ? T["_zod"]["output"] : unknown;

The type behavior remains exactly the same, but without the redundant mapped type transformations.

Test plan

  • Tested with TypeScript 5.5.4 - all tests pass (283 test files, 2805 tests)
  • Tested with TypeScript 5.9.2 - all tests pass (283 test files, 2805 tests)
  • Verified recursive type definitions work correctly

Related

Fixes #5035

🤖 Generated with Claude Code

The Required<> utility type was redundant in both input and output type
definitions because the type guards already ensure these are required
properties. If they were optional, the conditions would fail and return
'unknown'. This redundant mapped type caused TS2615 circular reference
errors in TypeScript 5.9+.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@colinhacks
Copy link
Owner

Thanks for the excellent issue and PR. My heart dropped when I saw a TS 5.9 incompatibility with ts5.9. Glad this was an easy fix 😅 I guess those Required<> calls are vestigial...I forget why I ever added them.

@yz89122 yz89122 deleted the fix/remove-redundant-required-from-type-helpers branch August 5, 2025 08:27
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.

TypeScript 5.9+ causes TS2615 errors in recursive type definitions
2 participants