Material date-fns adapter

Viewed 1237

I'm currently switching from Moment.js to date-fns in my Angular app, but I'm facing an impediment.

I found as well an adapter made by angular @angular/material-date-fns-adapter and I added this in my material module:

{
    provide: DateAdapter,
    useClass: DateFnsAdapter,
    deps: [MAT_DATE_LOCALE],
},
{ provide: MAT_DATE_FORMATS, useValue: DateHelpers.MatDateFormat }

and I'm getting the following error which I can't manage to solve:

Error: node_modules/@angular/material-date-fns-adapter/adapter/date-fns-adapter.d.ts:5:45 - error TS2314: Generic type 'DateAdapter<D>' requires 1 type argument(s).

5 export declare class DateFnsAdapter extends DateAdapter<Date, Locale> {

Is anyone who faced this issue or knows how to fix it?

1 Answers

I was facing the same issue.

Root cause was me npm installing @angular/material-date-fns-adapter with a different version to the rest of angular/material.

It turns out, date-fns is not possible with my version of material, so I will try to upgrade the website to latest version of material. Wish me luck.

The angular material documentation website lets you select the version. Maybe it's the same for you.

Related