You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some of the typings for the DatePicker component that are passed directly to flatpickr are incomplete (missing some of the possible types), meaning that Typescript can add a warning/error to a provided prop even though the value is valid to flatpickr.
enable, disable
I found this with the enable and disable props. In @carbon/react they are of type string[]:
While in flatpickr they are of type DateLimit<DateOption>[], which is equivalent to (Date | string | number | { from: Date | string | number, to: Date | string | number } | ((date: Date) => boolean))[]:
Add one of the specified props to DatePicker with a Date value or one of the other unsupported value types ( eg: enable={[(date) => ![0, 6].includes(date.getDay())]} or minDate={new Date()})
Run tsc --noemit
You should receive an error/warning (depends on configuration) from Typescript
src/main.tsx:11:18 - error TS2322: Type '(date: any) => boolean' is not assignable to type 'string'.
11 enable={[(date) => ![0, 6].includes(date.getDay())]}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/main.tsx:12:9 - error TS2322: Type 'Date' is not assignable to type 'string | number | undefined'.
12 minDate={new Date()}
~~~~~~~
Suggested Severity
Severity 4 = Unrelated to a user task, has a workaround or does not need a workaround.
Package
@carbon/react
Browser
No response
Package version
v1.53.1
React version
v18.2.0
Description
Some of the typings for the
DatePicker
component that are passed directly to flatpickr are incomplete (missing some of the possible types), meaning that Typescript can add a warning/error to a provided prop even though the value is valid to flatpickr.enable
,disable
I found this with the
enable
anddisable
props. In@carbon/react
they are of typestring[]
:carbon/packages/react/src/components/DatePicker/DatePicker.tsx
Line 251 in c90b401
While in flatpickr they are of type
DateLimit<DateOption>[]
, which is equivalent to(Date | string | number | { from: Date | string | number, to: Date | string | number } | ((date: Date) => boolean))[]
:https://github.com/flatpickr/flatpickr/blob/548330e6e18871d6ca1ca78746c0e89cb12a0303/src/types/options.ts#L124
minDate
,maxDate
Also
minDate
andmaxDate
are missing theDate
type since they are of typeDateOption
(Date | string | number
) in flatpickrhttps://github.com/flatpickr/flatpickr/blob/548330e6e18871d6ca1ca78746c0e89cb12a0303/src/types/options.ts#L156
And just
string | number
in@carbon/react
carbon/packages/react/src/components/DatePicker/DatePicker.tsx
Line 345 in c90b401
Reproduction/example
https://stackblitz.com/edit/vitejs-vite-81ltbd?file=src%2Fmain.tsx
Steps to reproduce
@carbon/react
DatePicker
with a Date value or one of the other unsupported value types ( eg:enable={[(date) => ![0, 6].includes(date.getDay())]}
orminDate={new Date()}
)tsc --noemit
Suggested Severity
Severity 4 = Unrelated to a user task, has a workaround or does not need a workaround.
Application/PAL
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: