I'm currently learning Flow by applying it to an existing project and looking to annotate function parameters as a Moment.JS objects.
Using flow-typed I was able to install a library definition for Moment.JS which appears to have the type I'm looking for:
declare class moment$Moment {
static ISO_8601: string;
static (string?: string, format?: string|Array<string>, locale?: string, strict?: bool): moment$Moment;
static (initDate: ?Object|number|Date|Array<number>|moment$Moment|string): moment$Moment;
static unix(seconds: number): moment$Moment;
static utc(): moment$Moment;
...
However when I try to annotate function parameters as Moment.JS objects, Flow fails to recognize them as such. In the following function startDate
and endDate
are Moment.JS date objects.
const filterByDateWhereClause = (startDate: Moment, endDate: Moment): string => {...};
Flow gives the following error:
const filterByDateWhereClause = (startDate: Moment, endDate: Moment): string =>
^^^^^^ identifier `Moment`. Could not resolve name
Is this even possible with Flow? Or do I need to duplicate the type
for the Moment.JS object identical to the one in the library definition provided by flow-type? I'd prefer not to do this as the libdef is fairly lengthy.
For example:
declare class Moment {
static ISO_8601: string;
static (string?: string, format?: string|Array<string>, locale?: string, strict?: bool): moment$Moment;
static (initDate: ?Object|number|Date|Array<number>|moment$Moment|string): moment$Moment;
static unix(seconds: number): moment$Moment;
static utc(): moment$Moment;
...
const filterByDateWhereClause = (startDate: Moment, endDate: Moment): string => {...};
What am I missing?
moment$Moment
won't work for me, perhaps because I'm using Webpack so there's no global namespace? The two import methods worked. – Thirtieth