Closed micalevisk closed 3 months ago
oh interesting. nice suggestion. i'll try to do this sometime this year if i get time 👍
just thinking (i havent tested) - but is this maybe an esmodule import / export issue ? I know es modules a bit weird about declaring multiple classes in one file and circular references sometimes
but the final code (after tsc compilation) will be in CJS, not in ESM
and I tried with classes declared in separated files as well. I don't think this is a circular related issue
This is supported on Nestjs now
The usage of
@Inject()
without some provider's token on parameters is invalid (due to TS limitations, AFIAK). And I didn't succeded on making it fail at build time. So, as of now, we will see a 'dependency not found' error at runtime. This could confuse people.My suggestion is adding a rule to forbids such usage
code
```ts import { Module, Inject, forwardRef } from '@nestjs/common'; class FooService {} @Module({ providers: [FooService] }) export class AppModule { @Inject(forwardRef(() => FooService)) public readonly service: FooService; @Inject() private readonly validInjectUsage: FooService constructor( /* @Inject(forwardRef(() => FooService)) private valid: FooService , @Inject(undefined) private valid2: FooService , @Inject('') private valid3: FooService // , */ @Inject() private invalid: FooService // <<< this should error out as 'you must pass a token' ) {} } ```