date-fns: Method expression is not of Function type

const subDays = require('date-fns/subDays');
subDays(new Date(), (offset + 6));

In this code, Webstorm shows error message "Method expression is not of Function type" for subDays(...);

How can I remove this message? The code works very well so I can't find any problems.

1 comment

Because of a way typings (declaration stubs) of date-fns are defined, type of subDays is inferred to `any`, thus the warning

Changing require to import will solve the problem:

import subDays from 'date-fns/subDays';

subDays(new Date(), 6);

Please sign in to leave a comment.