最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Typescript: How to say a variable is of type moment? - Stack Overflow

programmeradmin9浏览0评论

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?

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?

Share Improve this question edited Aug 16, 2017 at 5:38 Numé 3291 silver badge7 bronze badges asked Jul 14, 2017 at 8:13 aksaks 9,49111 gold badges52 silver badges81 bronze badges 1
  • what's the moment interface supposed to be? where is it defined? – toskv Commented Jul 14, 2017 at 8:14
Add a comment  | 

2 Answers 2

Reset to default 16

According to moment.d.ts

import * as moment from 'moment';

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

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

发布评论

评论列表(0)

  1. 暂无评论