Reputation: 8118
I need to define types for my current project for the following:
import toISOMonthString from 'react-dates/esm/utils/toISOMonthString';
The thing is, I tried the basic:
declare module "react-dates/esm/utils/toISOMonthString'" {}
But I have and error:
[ts] Invalid module name in augmentation. Module 'react-dates/esm/utils/toISOMonthString' resolves to an untyped module at '.../node_modules/react-dates/esm/utils/toISOMonthString.js', which cannot be augmented.
To make the PR in order to solve that should be easy, but I need to solve it locally for now.
Do you have any idea how to type this untyped files?
Upvotes: 1
Views: 3310
Reputation: 8118
A possible approach should be to create a .d.ts
file with the following:
declare module 'react-dates/esm/utils/toISOMonthString' {
import { MomentInput } from 'moment';
export default function(date: MomentInput): string;
}
Upvotes: 4
Reputation: 30919
Your declare module "react-dates/esm/utils/toISOMonthString'" {}
is being treated as a module augmentation because it appears in another module (a file with a top-level ES6 import or export). Move the declaration to a separate file so that it is treated as an original declaration of the module. (This is poorly documented; you can read a bit more about it here.)
Upvotes: 6