aks
aks

Reputation: 9491

Typescript: How to say a variable is of type moment?

I have an interface which has a callback and it takes two parameters which are moment object. Here is how it looks like

interface IProps {
  callback: (startDate: any, endDate: any) => void
}

This is working for me but I want to be more specific and say that they are not any but moment like so which results in an error:

interface IProps {
  callback: (startDate: moment, endDate: moment) => void
}

How can I fix this?

Upvotes: 8

Views: 7468

Answers (2)

Numé
Numé

Reputation: 329

According to moment.d.ts

import * as moment from 'moment';

interface IProps {
  callback: (startDate: moment.Moment, endDate: moment.Moment) => void
}

Upvotes: 16

Jameel
Jameel

Reputation: 3176

Import the moment interface/class to your file with: import { moment } from "moment";

Upvotes: 0

Related Questions