undefinedfix
Sign in

Why can't NPM run build pass generics

Pujianto edited in Mon, 08 Aug 2022

A template class is written, in which a service is injected, as follows:

export class MyClass<T extends Service>{

  constructor(protected modalService: NzModalService, protected service : T ) {
  }
}

After using the NPM run build command, the prompt is as follows:

ERROR in : Can't resolve all parameters for MyClass in ./././my-class.ts: ([object Object], ?).

How to solve the problem? Is it necessary to configure build?

2 Replies
jakab922
commented on Mon, 08 Aug 2022

Just inject a specific implementation class.

constructor(protected modalService: NzModalService, @Inject(BaseService) protected service : T ) {
}
Paloha
commented on Mon, 08 Aug 2022

It has nothing to do with the build script. When a TS file references MyClass, it does not give the parameter T. you should post the code of the class that injects MyClass, and specify the parameter after MyClass, such as MyClass < XXXX > for example