This rule raises an issue when Angular code gives an output binding an unnecessary alias, including a redundant alias identical to its property name.
Aliasing output bindings creates unnecessary complexity in your Angular components and directives. When an output property has a different name than its alias, developers must remember both names to use the component correctly.
This dual naming convention increases cognitive load and makes the codebase harder to maintain. It also breaks the principle of least surprise - developers expect the output name to match the property name.
Consistent naming between properties and their public API makes components more predictable and easier to understand, especially for team members who didn’t write the original code.
Aliased outputs can lead to confusion during development and maintenance. Team members may struggle to understand which name to use when binding to the output, leading to bugs and increased development time. The inconsistency also makes code reviews more difficult and reduces overall code quality.
Before removing an alias or renaming a member, check how the output is used. Removing an alias changes the public template binding and can break consumers. Renaming the TypeScript member can affect code references. Update those usages together when changing an output name.
When an alias is unnecessary, remove it from the @Output decorator and use the property name directly.
@Component()
class MyComponent {
@Output('change') valueChange = new EventEmitter(); // Noncompliant
}
@Component()
class MyComponent {
@Output() valueChange = new EventEmitter();
}
For the output() function, remove an unnecessary alias and use the property name directly.
@Component()
class MyComponent {
valueChange = output({ alias: 'change' }); // Noncompliant
}
@Component()
class MyComponent {
valueChange = output();
}
Likewise, remove unnecessary aliases from the outputs metadata array.
@Component({
outputs: ['valueChange: change'] // Noncompliant
})
class MyComponent {}
@Component({
outputs: ['valueChange']
})
class MyComponent {}
An alias is allowed when the original member name exactly matches a native DOM event name and the public alias does not. For example, exposing
valueChanged instead of change distinguishes a component output from the native change event. This applies to
output(), @Output(), and outputs metadata.
@Component({ selector: 'app-slider', template: '' })
class Slider {
change = output<number>({ alias: 'valueChanged' }); // Compliant
}
The event names are case-sensitive and come from Angular ESLint’s shared native-event set. It includes HTMLElement, Window, Document, and SVG
events, as well as deprecated, experimental, and vendor events. Prefixes and casing are not normalized: $change, _change,
onChange, and Change do not qualify. Aliases that expose a native event name, including change aliased to
click, receive no exception. Same-name aliases remain redundant.
Output aliases can distinguish events from directives that share an element. The rule accepts the following naming convention without checking for a collision in a template.
For components and directives, remove brackets and whitespace from the selector to form an event prefix. Use this prefix alone, or append the
property name with its first letter capitalized. For foo[bar] and a property named changed, the accepted aliases are
foobar and foobarChanged.
Directives with a literal element[attribute] selector can also capitalize the attribute’s first letter: fooBar or
fooBarChanged. Keep all other selector characters unchanged. These additional forms apply to @Output and
output() with literal aliases and statically named properties in unambiguous declarations:
@Directive({ selector: 'foo[bar]' })
class FooBarDirective {
@Output('fooBarChanged') changed = new EventEmitter();
event = output({ alias: 'fooBar' });
}
An alias that equals the property name remains redundant and is reported.
Aliases in the outputs array of a hostDirectives entry are also allowed, so a composed directive’s outputs can be exposed
under different public names.
@Component({
selector: 'app-menu',
template: '',
hostDirectives: [{
directive: FooBarDirective,
outputs: ['fooBarChanged: barChanged'] // Compliant
}]
})
class Menu {}