I want to know if it's possible to use (Typescript) generics in a Angular Route, in any way possible.
Best way would be if I could use generics with the component itself:
// the route:
{
path: 'user-a',
component: UserComponent<UserA> // other routes will use UserB and UserC
}
// the component:
@Component({...})
export class UserComponent<T> { ... }
This obviously gives an error, but it gives a good idea of what I want to accomplish.
Another method would be to use generics with the Resolver:
// the route:
{
path: '/user-b',
component: UserComponent,
resolve: { user: UserResolver<UserB> }
}
// the resolver:
export class UserResolver<T> implements Resolve<boolean> {}
This answer used this method, but for me it gives an error at UserResolver<UserB>
: "Value of type 'typeof UserResolver' is not callable. Did you mean to include 'new'?"
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…