打字稿:怎么说变量是一种类型的时刻?

aks*_*aks 4 javascript momentjs typescript

我有一个具有回调的接口,它有两个参数,即时刻对象.这是它的样子

interface IProps {
  callback: (startDate: any, endDate: any) => void
}
Run Code Online (Sandbox Code Playgroud)

这对我有用,但我想更具体一点,并说它们不是唯一的,但这样会导致错误:

interface IProps {
  callback: (startDate: moment, endDate: moment) => void
}
Run Code Online (Sandbox Code Playgroud)

我怎样才能解决这个问题?

小智 10

根据moment.d.ts

import * as moment from 'moment';

interface IProps {
  callback: (startDate: moment.Moment, endDate: moment.Moment) => void
}
Run Code Online (Sandbox Code Playgroud)