How can I specify the correct type for routes array in order to prevent the error:
TS2314: Generic type 'Route ' requires 1 type argument(s).
View code in TypeScript playground
interface Route<T> {
path: string
handler: () => T
}
class Router {
routes: Route[] = []
addRoute<T>(path: string, handler: Route<T>['handler']) {
this.routes.push({
path,
handler
})
}
}
const router = new Router()
router.addRoute<string>('home', () => '123')