Skip to content

fix(zod): DateTime, Bytes, and Decimal field inference for z.input#2685

Merged
ymc9 merged 7 commits into
zenstackhq:devfrom
sanny-io:fix/zod-datetime-input
May 31, 2026
Merged

fix(zod): DateTime, Bytes, and Decimal field inference for z.input#2685
ymc9 merged 7 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

    • Refined scalar type mappings used for schema validation to improve type accuracy and consistency.
  • Tests

    • Added type-level tests to verify correct input handling for date, binary, and numeric fields and ensure reliable validation behavior.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 26, 2026

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

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: 511b2666-e5b0-4b67-9313-0d5b1a9c42b1

📥 Commits

Reviewing files that changed from the base of the PR and between 050bd9c and f73c5e0.

📒 Files selected for processing (1)
  • packages/zod/src/types.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/zod/src/types.ts

📝 Walkthrough

Walkthrough

Updates FieldTypeZodMap to use concrete Zod types and explicit input/output type parameters (DateTime -> z.ZodDate; Decimal/Bytes -> z.ZodType<T, T>) and adds a type-level test that verifies z.input infers the expected field input types.

Changes

Zod scalar type mappings and input type verification

Layer / File(s) Summary
FieldTypeZodMap scalar type mappings
packages/zod/src/types.ts
DateTime now maps to z.ZodDate; Decimal and Bytes use explicit input/output z.ZodType<T, T> so z.input can infer correct input types.
Input type verification test
packages/zod/test/factory.test.ts
Adds a type-level test asserting z.input<typeof _userSchema> infers birthdate as `Date

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰
With Zod now speaking plainly, types align,
DateTime shows a face, not unknown this time.
Decimal and Bytes wear both input and out,
The schema sings true—no more type doubt.
Hop, code, hop—let forms and types rhyme!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: fixing Zod field mappings for DateTime, Bytes, and Decimal to enable proper z.input type inference.
Linked Issues check ✅ Passed The PR addresses issue #2673 by updating FieldTypeZodMap mappings for DateTime, Bytes, and Decimal to use concrete Zod types that support correct z.input inference, matching the stated objectives.
Out of Scope Changes check ✅ Passed All changes are scoped to the fix: updating type mappings in FieldTypeZodMap and adding a test to verify correct input type inference for the affected fields.

✏️ 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.


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.

@sanny-io sanny-io changed the title fix(zod): DateTime field inference for z.input fix(zod): DateTime, Bytes, and Decimal field inference for z.input May 29, 2026
@sanny-io
Copy link
Copy Markdown
Contributor Author

sanny-io commented May 30, 2026

The cast for bytesSchema is because otherwise the underlying value is inferred as uint8Array<ArrayBuffer> rather than uint8Array<ArrayBufferLike>, which is the default generic parameter of uint8Array and is the one present in the existing tests.

Copy link
Copy Markdown
Member

@ymc9 ymc9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @sanny-io , thanks for working on the fix!

I'm wondering if a simpler solution is to add a second type parameter to the z.ZodType usage to control the input type (like z.ZodType<Decimal, Decimal>). What do you think?

@sanny-io
Copy link
Copy Markdown
Contributor Author

@ymc9 I didn't know about that parameter. Will try that out later today and report back.

@sanny-io
Copy link
Copy Markdown
Contributor Author

@ymc9 everything looks good now.

Copy link
Copy Markdown
Member

@ymc9 ymc9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thank you! I'm merging it.

@ymc9 ymc9 merged commit fc100fc into zenstackhq:dev May 31, 2026
9 checks passed
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

2 participants