fix: restore onChange type inference for single date picker #6205
+104
−15
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
onChangecallback parameterProblem
After upgrading to 9.1.0, TypeScript could not infer the type of the
onChangeparameter:This caused the error: "Parameter 'x' implicitly has an 'any' type. (7006)"
Root Cause
Commit 3a82fd1 changed
selectsRange: trueandselectsMultiple: trueto optional (selectsRange?: trueandselectsMultiple?: true) in the discriminated union type. This prevented TypeScript from narrowing the union when neither prop is specified, causing all threeonChangesignatures 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:
This is acceptable because:
selectsRangeandselectsMultiplealready pass these props explicitly (required for runtime behavior)Test plan
type_inference_test.test.tsxto verify TypeScript can infer types without explicit annotationsFixes #6202
🤖 Generated with Claude Code