Object.constructor isn't implemented specifically enough
#4.586 aberto em 1 de set. de 2015
Métricas do repositório
- Stars
- (48.455 stars)
- Métricas de merge de PR
- (Mesclagem média 6d 17h) (9 fundiu PRs em 30d)
Description
Consider:
class Foo extends ([].constructor) {
}
[].constructor should be Array, which we aught to be able to extend. However, the checker complains on [].constructor that "Type 'Function' is not a constructor function type". Considering .constructor is quite explicitly the constructor function for the object, I believe this is a lie perpetuated by our lib.d.ts files. I think we need to go add appropriate self-constructor-referencing .constructor fields to each builtin.
Additionally consider the following:
class Bar {
}
class Foo extends ((new Bar()).constructor) {
}
The same thing but with a custom class rather than a builtin. We should know the correct type of .constructor here (the Bar class), but we don't - we just look at the members on Object.
In the first example, I believe it could be fixed with more precise lib files, but in the second case, I believe this is an instance of a field whose type should be known by the compiler, much like .prototype on the class itself is known.