【发布时间】:2019-10-09 22:19:07
【问题描述】:
我正在将一些代码移至 TS,并且一直在努力为一组路由函数定义一个类型。这就是他们的样子:
const root: Route = () => 'root'
root.child = () => `${root()}/child`
root.child.grandchild = () => `${root.child()}/grandchild`
我尝试在嵌套属性的索引签名旁边定义某种递归可调用类型或接口,但没有多大成功:
type Route = {
(): string
[key: string]: Route
}
关于我如何做到这一点的任何想法或想法?
【问题讨论】:
标签: typescript