google / google/closure-compiler
Feature Request: Ability to @extend a generic (templated) class
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
It would be really nice if the compiler would understand a class that extends a templated type.
Consider something like this:
``` js
/**
* @constructor
*/
function Foo() {
this.x = 'x';
};
/**
* @constructor
*/
function Bar() {
this.y = 'y';
};
/**
* @constructor
* @param {function(new: T)} FooOrBar
* @extends {T}
* @template T
*/
function Enhanced(FooOrBar) {
FooOrBar.call(this);
this.z = 'z';
};
/** @type Enhanced. */
var enhancedFoo = new Enhanced(Foo);
/** @type Enhanced. */
var enhancedBar = new Enhanced(Bar);
```
when I compile this code with the closure compiler I get a compiler warning:
> 'Could not resolve type in @extends tag of Enhanced'.
Obviously, the compiler needs to know the class hierarchy at compile time, But, it would be nice to at least be able to say to the compiler in a `@type` directive -- considering it's not uncommon to have class factories in JavaScript -- that type `EnhancedFoo` inherits `Enhanced` and `Foo`.
Contributor guide
Assessment
This issue has not been assessed yet.