Skip to content

Conversation

@martijnrusschen
Copy link
Member

Summary

  • Restores proper TypeScript type inference for onChange callback parameter
  • Reverts discriminated union changes that broke type narrowing
  • Adds type inference tests to prevent regression

Problem

After upgrading to 9.1.0, TypeScript could not infer the type of the onChange parameter:

<DatePicker
  onChange={(x) => {
    // x was inferred as 'any' instead of 'Date | null'
  }}
/>

This caused the error: "Parameter 'x' implicitly has an 'any' type. (7006)"

Root Cause

Commit 3a82fd1 changed selectsRange: true and selectsMultiple: true to optional (selectsRange?: true and selectsMultiple?: true) in the discriminated union type. This prevented TypeScript from narrowing the union when neither prop is specified, causing all three onChange signatures to be valid simultaneously.

Solution

Restore the required discriminators:

  • selectsRange: true (not optional)
  • selectsMultiple: true (not optional)

This allows TypeScript to properly narrow the type when neither prop is passed.

Impact on #6131

The original fix (#6131) was for wrapper components spreading props. Those users can work around this with a type assertion:

// Wrapper component workaround
<DatePicker {...(props as DatePickerProps)} />

This is acceptable because:

  1. The 99% use case (basic DatePicker) now has proper type inference
  2. Wrapper component authors are a smaller, more sophisticated audience who can use type assertions
  3. Users of selectsRange and selectsMultiple already pass these props explicitly (required for runtime behavior)

Test plan

  • Added type_inference_test.test.tsx to verify TypeScript can infer types without explicit annotations
  • Reverted test workarounds that added explicit type annotations
  • CI should pass type-check and tests

Fixes #6202

🤖 Generated with Claude Code

Reverts the discriminated union changes from commit 3a82fd1 that made
`selectsRange` and `selectsMultiple` optional in their respective union
branches. This broke TypeScript's ability to infer the onChange parameter
type when neither prop is specified.

The fix restores required `selectsRange: true` and `selectsMultiple: true`
in their respective union branches, allowing TypeScript to properly narrow
the type and infer `Date | null` for the default single-date case.

Users of range/multiple selection already pass these props explicitly
(required for runtime behavior), so this change aligns types with actual
usage patterns.

Wrapper components that need to spread props can use type assertions
as a workaround (see issue #6131 for details).

Also adds explicit type inference tests to prevent regression.

Fixes #6202

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Jan 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.29%. Comparing base (644f2f5) to head (144a0d4).
⚠️ Report is 23 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6205      +/-   ##
==========================================
- Coverage   99.31%   99.29%   -0.03%     
==========================================
  Files          30       30              
  Lines        3810     3810              
  Branches     1639     1659      +20     
==========================================
- Hits         3784     3783       -1     
- Misses         25       26       +1     
  Partials        1        1              

☔ 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.

@martijnrusschen martijnrusschen merged commit a58bf4f into main Jan 5, 2026
5 of 6 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.

onChange type breaks after updating to 9.1.0

2 participants