ts初学者?
这个该怎么改
interface MetaObj {
displayName: string
path: string
active: string | null
headActive?: string
}
type route = {
path: string,
index: string,
redirect: string | null,
name: string,
meta: MetaObj,
icon: string,
iconName: string,
children: route[] | null,
}
class RouteDo<T extends route> {
constructor(private routes: T[]){}
public formatRoutes(routes: T[] = this.routes, parentNode?: T): T[]{
routes.forEach((item: T) => {
if(parentNode){
item.meta.headActive = parentNode.meta.headActive
} else {
item.meta.headActive = item.index
}
if(item.children && item.children.length) {
item.children = this.formatRoutes(item.children, item)
}
})
return routes
}
}
另定义一个接口描述描述它的chilren属性为当前类的数组
route再通过泛型的方式定义它的children属性