Theo's Typesafe CultTTC
Theo's Typesafe Cult4y ago
5 replies
6enton

Nested Generic Types??

Heyo

I have a class that takes in an object in it's constructor. I'd like the object to be a nested object with this type:
type Route = (ctx: Context) => Response<unknown>
type Router = {[key: string]: Route | Router}

class MyRouter<T extends Router>{
  routes: T
  constructor(r: T){ this.routes = r}
}

This works, but it's not generic so I don't get the autocompletion I'm after. My attempts at making this generic fail.
Was this page helpful?