【发布时间】:2018-12-27 08:55:48
【问题描述】:
我对如何在 TS 中进行这种类型转换感到困惑。我正在定义一个需要是这种类型的类方法(https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react-big-calendar/index.d.ts#L229)
我正在尝试做这样的事情......
public onSelectSlot: Pick<BigCalendarProps<InterviewEvent>, 'onSelectSlot'> = (slot) => {
this.setCreateDialog(true, slot.slots.slice(0, -1));
}
但这不起作用,我无法弄清楚如何将函数 arg 类型从链接中的该接口中拉出。我该怎么做?
【问题讨论】:
-
(slot: { start: stringOrDate, end: stringOrDate, slots: Date[] | string[], action: 'select' | 'click' | 'doubleClick' }) => ...? -
对...但我想避免从@types模块中逐字复制类型,以防将来发生变化
-
然后请bigcalendar的作者定义并导出一个命名接口。或者自己定义。
标签: typescript