Inputs and outputs declared on a base class aren't credited when a subclass in another file uses them
What happened?
An @Directive() base class declares input() and output() members. A component in another file extends it, reads the inputs (in its class and in its template) and emits the output. All three are still reported on the base class.
Reproduction
package.json:
{ "name": "repro", "private": true, "dependencies": { "@angular/core": "20.0.0" } }
src/main.ts:
import { Child } from './child.component';
console.log(Child);
src/base.ts:
import { Directive, input, output } from '@angular/core';
@Directive()
export abstract class Base {
readonly readInSubclassTs = input('');
readonly readInSubclassTemplate = input('');
readonly emittedBySubclass = output<void>();
}
src/child.component.ts:
import { Component } from '@angular/core';
import { Base } from './base';
@Component({ selector: 'x-child', template: '<p>{{ readInSubclassTemplate() }}</p>' })
export class Child extends Base {
log(): string {
this.emittedBySubclass.emit();
return this.readInSubclassTs();
}
}
Run fallow dead-code --unused-component-inputs --unused-component-outputs. It reports, all in src/base.ts:
- input
readInSubclassTs - input
readInSubclassTemplate - output
emittedBySubclass
Expected behavior
Reads and emits in subclasses, including their templates, should credit the base-class members. unused-class-members already credits through inheritance (#130, #4199). The component input and output rules don't.
Fallow version
3.36.0
Operating system
macOS
Context
This accounts for about 70 unused-component-inputs and 11 unused-component-outputs findings in our codebase. Examples are abstract avatar, card and import-shell base classes.
Released in v3.43.2 (npm install [email protected]).
A component or directive that extends a base class from another file now counts the inputs and outputs that the base class declares, from its class body and its template. This works for a direct extends, through an intermediate class, and through a re-export. Your subclass example should no longer report the base-class inputs.
Thanks again for the report.
Thanks for the fast turnaround fixing all of these reports, much appreciated! Really loving fallow so far, it's a fantastic tool ❤️
Thanks for all the feedback @mattlewis92 it's really appreciated. If you have any more don't hesitate to file issues!