darraghoriordan / eslint-plugin-nestjs-typed

Some eslint rules for working with NestJs projects
http://www.darraghoriordan.com
171 stars 34 forks source link

Rule to detect that an injected dependency has no @Injectable() decorator on the defining class #67

Closed spotlesscoder closed 1 year ago

spotlesscoder commented 1 year ago

Consider the following classes

@Injectable()
export class MyClassA {
  constructor(private readonly myInstaceB : MyClassB) {}

  //[...] implementation
}
export class MyClassB {

  //[...] implementation
}

Note that class B is not injectable. In the constructor line in class A, I want the eslint check to highlight that the myInstanceB cannot be instantiated because MyClassB is not injectable

micalevisk commented 1 year ago

actually, that code works as expected.

since that MyClassA provider is annotated with @Injectable(), MyClassA is said injectable, which means that we can inject providers into ti. It is not the other away around, as you said. MyClassB didn't has dependencies so it doesn't need to be marked as a injectable.

We don't have to add the @Injectable() to a class unless we want to inject something in that class, or if that class is using the @Inject() parameter decorator.

micalevisk commented 1 year ago

if you don't believe me :p

image

micalevisk commented 1 year ago

@darraghoriordan I think you can close this :)