-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Rule Proposal: Override checking for interfaces #3608
Comments
Could you explain the usecase for override on interfaces? I can think of a few cases that you might want to but they're exceedingly rare. Rare enough that I don't think such a rule would belong in this project. |
Main usecase for us are optional properties / methods in the interface: interface ISomething {
doSomething?: () => void;
}
class Something implements ISomething {
doSomething: () => {console.log("Something")}
} In this case it is possible to rename or remove the |
I was expecting you to show a usecase like interface I { method(): string }
interface II extends I { method(): 'a' } Your terminology is wrong - your usecase is not for overrides. The two are very different levels. One is a code safety and correctness issue. Overriding a base class's method means you want to change how it works on your subclass. OTOH, implementing an interface just ensures your code adheres to some contract. I'll be honest when I say that the tslint plugin conflating the two is not great. I understand the intention, but the effect is just confusion. |
Thank you for the detailed explanation. I hadn't thought about this distinction but it makes sense. I was probably used to add Still, I think bugs could be introduced in my above example. If you rename |
Have you considered raising this with the TS folks? |
Only found this comment so far on the PR which added the override keyword for classes:
However if it is only me being interested in this feature I can just continue to use the tslint rule in eslint (if I can get it working again) and I'll probably also create a ticket in TypeScript. Not sure though if it'll be accepted and even if it does, probably not coming soon (see above). |
Revisiting this issue. Whilst I do see value in this lint rule, due to the requirement for additional comment syntax and associated infra - I don't think it will have broad enough applicability to exist within this project specifically. I think it's a great idea though! You're very free to build on top of our tooling within another eslint-plugin which is better suited, or within a new plugin entirely. Thanks for the issue! |
I understand. Thank you for your consideration and explanation! |
The new
override
keyword in TS4.3 works for classes but not for interfaces.The ts-lint rule (https://github.com/hmil/tslint-override) supported both. We currently still have to use the tslint rule because of that.
Would be great to have a rule which supports override for interfaces.
See issue #293.
The text was updated successfully, but these errors were encountered: