Skip to content

fix: improve DatePickerProps discriminated union type inference#6100

Closed
martijnrusschen wants to merge 1 commit intomainfrom
fix/issue-5391-type-discriminated-union
Closed

fix: improve DatePickerProps discriminated union type inference#6100
martijnrusschen wants to merge 1 commit intomainfrom
fix/issue-5391-type-discriminated-union

Conversation

@martijnrusschen
Copy link
Copy Markdown
Member

This fix addresses issues #5391 and #5198 where TypeScript was not properly inferring types based on selectsRange and selectsMultiple props.

The problem was that using 'never' as the discriminant type for optional properties didn't allow TypeScript to properly narrow the union type.

Changes:

  • Changed selectsRange?: never to selectsRange?: false | undefined
  • Changed selectsMultiple?: never to selectsMultiple?: false | undefined
  • Updated test file to use correct type for selectsMultiple prop

This allows TypeScript to correctly infer:

  • onChange receives Date | null when selectsRange is false/undefined
  • onChange receives [Date | null, Date | null] when selectsRange is true
  • onChange receives Date[] | null when selectsMultiple is true

Fixes #5391
Fixes #5198

This fix addresses issues #5391 and #5198 where TypeScript was not properly
inferring types based on selectsRange and selectsMultiple props.

The problem was that using 'never' as the discriminant type for optional
properties didn't allow TypeScript to properly narrow the union type.

Changes:
- Changed selectsRange?: never to selectsRange?: false | undefined
- Changed selectsMultiple?: never to selectsMultiple?: false | undefined
- Updated test file to use correct type for selectsMultiple prop

This allows TypeScript to correctly infer:
- onChange receives Date | null when selectsRange is false/undefined
- onChange receives [Date | null, Date | null] when selectsRange is true
- onChange receives Date[] | null when selectsMultiple is true

Fixes #5391
Fixes #5198
@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 4, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.14%. Comparing base (f318d4b) to head (c154ff9).
⚠️ Report is 36 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6100   +/-   ##
=======================================
  Coverage   99.14%   99.14%           
=======================================
  Files          30       30           
  Lines        3612     3620    +8     
  Branches     1551     1555    +4     
=======================================
+ Hits         3581     3589    +8     
  Misses         29       29           
  Partials        2        2           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

Date Picker Type issue Typescript error with missing selectsMultiple

1 participant