Commit b38a660
committed
fix: improve DatePickerProps discriminated union type inference
This fix addresses issue #5391 where TypeScript was not properly inferring
the onChange callback type 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 #53911 parent f318d4b commit b38a660
2 files changed
+8
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
218 | 218 | | |
219 | 219 | | |
220 | 220 | | |
221 | | - | |
222 | | - | |
| 221 | + | |
| 222 | + | |
223 | 223 | | |
224 | 224 | | |
225 | 225 | | |
| |||
230 | 230 | | |
231 | 231 | | |
232 | 232 | | |
233 | | - | |
| 233 | + | |
234 | 234 | | |
235 | 235 | | |
236 | 236 | | |
| |||
240 | 240 | | |
241 | 241 | | |
242 | 242 | | |
243 | | - | |
| 243 | + | |
244 | 244 | | |
245 | 245 | | |
246 | 246 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
| 17 | + | |
21 | 18 | | |
22 | 19 | | |
23 | 20 | | |
| |||
28 | 25 | | |
29 | 26 | | |
30 | 27 | | |
31 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
32 | 31 | | |
33 | 32 | | |
34 | 33 | | |
| |||
0 commit comments