Field Injection (ARCH3200)
Key typescript.quality.field-injection · Severity warning · Category quality
Field/property injection hides dependencies, breaks immutability, and makes the class hard to instantiate without the DI container, lowering testability. Dependencies should be taken through the constructor.
Incorrect
Section titled “Incorrect”class InvoiceService { @Inject() private mailer!: Mailer;
send() { this.mailer.deliver(); }}Correct
Section titled “Correct”class InvoiceService { constructor(private readonly mailer: Mailer) {}
send() { this.mailer.deliver(); }}Inject dependencies through readonly constructor parameters instead of field annotations.