New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[no-useless-constructor] constructor
with super(someArgs)
is not useless in Angular
#1164
Comments
We can use following workaround temporarily: class B implments A {
constructor(protected injector: Injector) {
super(injector);
}
} But if class A {
private http: HttpClient
constructor(private injector: Injector) {
this.http = this.injector.get(HttpClient)
}
}
class B implements A {
constructor(private _injector: Injector) {
super(_injector)
}
} |
Why do you keep writing Could you please explain why you need the constructor on the child class? Unless I'm mistaken, this is perfectly valid code, which does exactly the same thing, without the useless constructor: class A {
protected http: HttpClient
constructor(protected injector: Injector) {
this.http = this.injector.get(HttpClient)
}
}
class B extends A { } |
Oh sorry, it should be B's constructor is required in favor of |
Have you got some docs on why the constructor is explicitly needed on the child? Unless I'm mistaken it shouldn't need it explicitly, as the child should implicitly inherit the parent's constructor. |
@bradzacher Just take https://stackblitz.com/edit/angular-gh3sf4 as an example. |
Please be careful with your @ tagging. You tagged the wrong account. Looking into this, I have no idea why it's required. I think angular statically analyses the file by itself? I'm not sure, the custom compiler is a black box to me. We don't want to encode the semantics of angular into typescript. If you'd like this functionality, I'd suggest getting a rule created in a plugin like eslint-plugin-angular. |
@bradzacher Thx for your patients. I will open a feature request issue at angular-eslint then. |
Repro
Expected Result
No error report
Actual Result
Error
Versions
@typescript-eslint/eslint-plugin
2.6.0
@typescript-eslint/parser
2.6.0
TypeScript
3.6.4
ESLint
6.6.0
node
13.0.1
npm
6.12.0
The text was updated successfully, but these errors were encountered: