google / google/closure-compiler

Specify inheritance for static methods on interfaces

Open
#2,983 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

ES6 classes have class-side inheritance, so that the following code should typecheck correctly:

```js
class Foo {
static foo(/** string */ arg) {}
}
class Bar extends Foo {
static foo(arg) { assertString(arg); }
}
```

But if `Foo` were declared as an `@interface` and `Bar` as `@implements {Foo}`, it's less clear. There are existing cases where concrete static methods on interfaces are used as (e.g.) factory methods, and since the uncompiled code does not actually link the interface to the implementation, they will not show up on the implementation - the compiler would need to enforce that they're implemented, which is not feasible nor desired. Nor does the mechanism by which we handle class-side inheritance for extended classes handle this case particularly well, since the interface does not appear in the prototype chain.

But an `@abstract` static method on an interface is basically meaningless, so one could imagine redefining it to mean that any implementing class needs to have this static method. Is this something we want to do?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.