Material-ui-pickers: Property 'getDaysInMonth' is missing in type 'DateFnsUtils' but required in type 'IUtils<unknown>

Created on 27 Aug 2020  路  5Comments  路  Source: mui-org/material-ui-pickers

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.

https://github.com/dmtrKovalenko/date-io/issues/446

  • [x] The issue is present in the latest release.
  • [x] I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 馃槸

TS2322: Type 'typeof DateFnsUtils' is not assignable to type 'new (...args: any) => MuiPickersAdapter'. 聽聽Property 'getDaysInMonth' is missing in type 'DateFnsUtils' but required in type 'IUtils'.

Expected Behavior 馃

No TS error.

Steps to Reproduce 馃暪

https://codesandbox.io/s/mui-datetimepicker-dateadapter-typescript-error-forked-6wqm0?file=/index.tsx

The code that produces the error is below:
...
<MuiPickersProvider dateAdapter={DateFnsUtils}> </MuiPickersProvider>
...

Your Environment 馃寧

| Tech | Version |
| ----------- | ------- |
| @material-ui/core | v4.11.0 |
| @material-ui/pickers | v4.0.0-alpha.12 |
| React |16.13.1|
| TypeScript |4.0.2|

typescript

Most helpful comment

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;
  }
}

All 5 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

danmce picture danmce  路  3Comments

katy6514 picture katy6514  路  3Comments

filipenevola picture filipenevola  路  4Comments

nicky-dev picture nicky-dev  路  3Comments

idrm picture idrm  路  3Comments