The TypeScript error happens with alpha10 & alpha12. I have date-fns 2.15.0 installed.
The problem exist because author forgot to publish version 2.9.0 of @date-io/date-fns.
TS2322: Type 'typeof DateFnsUtils' is not assignable to type 'new (...args: any) => MuiPickersAdapter
No TS error.
The code that produces the error is below:
...
<MuiPickersProvider dateAdapter={DateFnsUtils}>
</MuiPickersProvider>
...
| Tech | Version |
| ----------- | ------- |
| @material-ui/core | v4.11.0 |
| @material-ui/pickers | v4.0.0-alpha.12 |
| React |16.13.1|
| TypeScript |4.0.2|
while we are still waiting for a fix, here is a fast workaround:
import DateFnsUtils from "@material-ui/pickers/adapter/date-fns";
declare module "@material-ui/pickers/adapter/date-fns" {
export default class DateFnsUtils {
getDaysInMonth(value: Date): number;
}
}
Getting this error as well, with a slightly different message. Including it here in case to get more search hits.
ERROR in [at-loader] ./node_modules/@date-io/date-fns/build/date-fns-utils.d.ts:4:22
TS2420: Class 'DateFnsUtils' incorrectly implements interface 'IUtils<Date>'.
Property 'getDaysInMonth' is missing in type 'DateFnsUtils' but required in type 'IUtils<Date>'.
@TrejGun I found out what was causing this for me-- according to the official site these pickers only work with v1.x of date-io/date-fns, etc.
After uninstalling date-io (which is now at 2.x) and reinstalling @date-io/[email protected] I was good to go.
@AlexArendsen The issue is for v4.0.0-alpha, while your workaround can work with v3, it doesn't solve the issue with the latest version.
resolved
Most helpful comment
while we are still waiting for a fix, here is a fast workaround: