Typescript: 如何声明一个变量的类型为 moment?

7
我有一个接口,它有一个回调函数,并且需要两个参数,这两个参数都是moment对象。以下是示例代码:
interface IProps {
  callback: (startDate: any, endDate: any) => void
}

这对我来说是有效的,但我想更具体地说,它们不是任何时刻,而是像这样的时刻,这会导致错误:

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

我该如何解决这个问题?

Moment接口应该是什么?它在哪里定义? - toskv
2个回答

16
根据 moment.d.ts
import * as moment from 'moment';

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

0

使用以下代码将 moment 接口/类导入到您的文件中: import { moment } from "moment";


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接