#is not generic

18 messages · Page 1 of 1 (latest)

dusty ridge
#

ParentFormComponent

export class ParentFormComponent implements OnInit<T> {   // ERROR Type 'OnInit' is not generic.ts(2315)
                                                          // Cannot find name 'T'
...
  public currentPage: ParentFormComponent<T>;  // ERROR Cannot find name 'T'

UserPerimeterComponent

export class UserPerimeterComponent
  extends ParentFormComponent<User>  // ERROR Type 'ParentFormComponent' is not generic
  implements OnInit
{

an old project was working well in apprenticeship.
I switched to Angular 20 and reinstalled Eslint
suddenly, it gives me a new one at the level of class inheritance.
I don't understand

scarlet stratus
#

These are valid errors, OnInit is not generic and neither is ParentFormComponent. "Not generic" means it doesn't have any type parameters, thus you can't pass any. Trying to pass type parameters to a class without any type parameters is an error. This should have been an error before as well.

dusty ridge
#

thanks
yes unfortunately I end up with a project of 10,000 lines with strict mode removed and other horrible stuff
so to solve the problem I can't pass USER?

scarlet stratus
#

I am not sure why you wanted to pass it, it achieves nothing

dusty ridge
#

public currentPage: ParentFormComponent<T>;

the goal I believe is to pass User as T
so I delete and put User instead of T in parentForm?

scarlet stratus
#

Then ParentFormComponent needs to have a generic argument as well

dusty ridge
#

sorry I don't know what that means?
a small example?

scarlet stratus
#

But you can't directly pass generic args to components in Angular, because the component is instantiated in your template (e.g. <app-parent-form-component>). The generic arguments must be inferrable from inputs

dusty ridge
#

All right.
can you help me, how to do this?

#

or have you a doc? source ?

scarlet stratus
#

Well I don't know what your goal is. Why do you have a generic argument here?

dusty ridge
#

so that in ParentFormComponent the T represents User

and so in this component all the T's are in fact User

I don't know what else to tell you.
or maybe I didn't understand anything 🙂

#

look at currentPage it uses T

scarlet stratus
#

Then add a generic parameter to the component

#

So that you can pass it

dusty ridge
#

i don't understand "Then add a generic parameter to the component"

#

how to do this ?