Skip to content
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

methods implemented by BaseDriver cannot have their types narrowed in subclasses via mixin interfaces #18764

Open
boneskull opened this issue Jun 13, 2023 · 1 comment
Labels
DX developer experience (extension authoring, contributing, etc.)

Comments

@boneskull
Copy link
Contributor

That was a mouthful. This arises in getLog(), findElOrEls, etc.

The problem is that a subclass cannot both extend a base class with some method foo() and an interface with some method foo() unless foo() is exactly the same, if we are to mix interfaces into subclasses (e.g., like FakeDriver).

Without the mixin interfaces applied to the subclasses via declaration merging, getLog() and such can provide more narrow types. I'm unsure if this is specific to declaration merging. It seems there will always be tradeoffs, no matter the route we go.

I don't know of a "fix", but if narrowed types are needed (e.g., getLog() returns something besides any, which it should) the workaround would be to move any method implemented by BaseDriver into the subclass proper and out of whatever mixin it's in. e.g., FakeDriver's getLog() should move into FakeDriver proper.

There may be room for some incremental improvements. Since BaseDriver's findElOrEls only exists because a convenience function expects it to be there, declaring BaseDriver as abstract and making findElOrEls an abstract function might allow for some leeway. But I don't see any general solution to getLog() at this time, since it needs to be implemented in BaseDriver.

unsure if this needs to be an issue or is more of a public service announcement. that announcement? classical inheritance is bad actually 😝

@boneskull boneskull added the DX developer experience (extension authoring, contributing, etc.) label Jun 13, 2023
@jlipps
Copy link
Member

jlipps commented Jun 13, 2023

heh. I think making this a PSA is fine for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX developer experience (extension authoring, contributing, etc.)
Projects
None yet
Development

No branches or pull requests

2 participants