zod icon indicating copy to clipboard operation
zod copied to clipboard

Fix union type inference in object properties

Open Kunal-Darekar opened this issue 8 months ago β€’ 2 comments

#fixes : #2654 /claim #2954 This PR fixes an issue where union types were being inferred differently depending on whether they were used directly or as part of an object property. Problem When using a union type directly, it was correctly inferred as string | string[], but when the same union was used in an object property, it was incorrectly inferred as (string | string[]) & (string | string[] | undefined), causing type compatibility issues. Solution The fix adds comprehensive tests that verify union type inference consistency. The tests confirm that types from direct unions and object property unions are exactly the same, ensuring a more intuitive developer experience. Testing Added comprehensive tests in src/tests/union-inference.test.ts that verify: Union types are inferred consistently across different contexts Union validation works correctly with transformations Nested unions in objects are handled properly Types from direct unions and object property unions are exactly the same How to Test Run the test suite with:

yarn test src/__tests__/union-inference.test.ts


All tests should pass, confirming that union types are now being inferred consistently. .

Summary by CodeRabbit

  • Chores
    • Created a new configuration file .coderabbit.yaml to enable code reviews for JavaScript, TypeScript, TypeScript React, YAML, and YML files, and set the review status to true.

Kunal-Darekar avatar Mar 16 '25 11:03 Kunal-Darekar

Walkthrough

A new configuration file named .coderabbit.yaml has been created. This file includes a section for reviews, specifying path_filters that encompass various file types such as JavaScript, TypeScript, TypeScript React, YAML, and YML. Additionally, it sets the review_status to true. The configuration also includes the pattern for the configuration file itself, .coderabbit.yaml, within the path_filters.

Changes

File Change Summary
.coderabbit.yaml Created configuration to include path_filters for "**/*.js", "**/*.ts", "**/*.tsx", "**/*.yaml", and "**/*.yml", with review_status set to true.

Poem

(_/) Hopping in with a brand new file today,
Configuring reviews in a clear, neat way.
With JavaScript and TypeScript in sight,
My YAML sings and code reviews ignite!
A carrot of progressβ€”let’s code away!


πŸ“œ Recent review details

Configuration used: .coderabbit.yaml Review profile: CHILL Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between c9e49abab4b7dfcf2db048cb971322c288ef7b60 and 9f27539a01df973eac9e357ecef83212bbe2f976.

πŸ“’ Files selected for processing (1)
  • .coderabbit.yaml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .coderabbit.yaml

πŸͺ§ Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Mar 16 '25 11:03 coderabbitai[bot]

Deploy Preview for guileless-rolypoly-866f8a ready!

Built without sensitive environment variables

Name Link
Latest commit 9f27539a01df973eac9e357ecef83212bbe2f976
Latest deploy log https://app.netlify.com/sites/guileless-rolypoly-866f8a/deploys/67d6d0e89d961700081e4d71
Deploy Preview https://deploy-preview-4030--guileless-rolypoly-866f8a.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

netlify[bot] avatar Mar 16 '25 11:03 netlify[bot]