Skip to content

fix(zod): DateTime field inference for z.input#2685

Open
sanny-io wants to merge 2 commits into
zenstackhq:devfrom
sanny-io:fix/zod-datetime-input
Open

fix(zod): DateTime field inference for z.input#2685
sanny-io wants to merge 2 commits into
zenstackhq:devfrom
sanny-io:fix/zod-datetime-input

Conversation

@sanny-io
Copy link
Copy Markdown
Contributor

@sanny-io sanny-io commented May 26, 2026

Closes #2673

Summary by CodeRabbit

  • Bug Fixes

    • Improved type checking accuracy for DateTime fields in generated schemas, ensuring correct type inference during schema generation.
  • Tests

    • Added type-level validation tests for DateTime field type inference to extend coverage of scalar type handling.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1922d702-6b7c-4207-b591-98277578c317

📥 Commits

Reviewing files that changed from the base of the PR and between a43dff5 and 3c9b946.

📒 Files selected for processing (2)
  • packages/zod/src/types.ts
  • packages/zod/test/factory.test.ts

📝 Walkthrough

Walkthrough

DateTime scalar type mapping changed from generic z.ZodType<Date> to concrete z.ZodDate to enable proper z.input type inference. A test added to validate the birthdate field correctly infers input type as Date | null | undefined.

Changes

DateTime Type Inference Fix

Layer / File(s) Summary
DateTime scalar type mapping specification
packages/zod/src/types.ts
FieldTypeZodMap.DateTime now maps to z.ZodDate instead of generic z.ZodType<Date>, providing concrete type information for z.input inference.
Input type inference validation
packages/zod/test/factory.test.ts
New test verifies makeModelSchema('User') correctly infers the birthdate field input type as Date | null | undefined using z.input<typeof _userSchema>.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A Zod type tweak, oh what a sight!
From generic woes to concrete light,
DateTime now speaks with clarity true,
Input types shine, no more "unknown" hue—
React Hook Form dances, our types align right! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: fixing DateTime field inference for z.input by updating the Zod type mapping from z.ZodType to z.ZodDate.
Linked Issues check ✅ Passed The PR directly addresses issue #2673 by updating FieldTypeZodMap to use z.ZodDate instead of z.ZodType, enabling correct z.input inference for DateTime fields, and adds tests to verify the fix.
Out of Scope Changes check ✅ Passed All changes are scoped to addressing issue #2673: updating the DateTime type mapping and adding corresponding test coverage, with no unrelated modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/zod/src/types.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

packages/zod/test/factory.test.ts

ESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

makeModelSchema: DateTime fields infer as unknown in z.input

1 participant