microsoft / microsoft/TypeScript
Subclass method is not allowed (TS2425) if the parent class has a property of type any with the same name
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.3k
- Merge medio
- 2 d 4 h
- PR fusionados (30 d)
- 132
Descripción
TypeScript appears to treat class methods as something fundamentally different from a class prototype property of type function. This is not in agreement with the standard semantics of ES6.
TypeScript Version: all versions, as far as I have been able to test.
Search Terms: method member property any parent class subclass
Code
class Super {
prop: any;
}
class Derived extends Super {
prop() {}
}
Expected behavior: should compile without a problem. Note that by the ES6 standard, the above definition of Derived is equivalent to the following, which TypeScript compiles without a problem:
class Derived extends Super {}
Derived.prototype.prop = function(){};
Actual behavior:
Error TS2425: Class 'Super' defines instance member property 'prop', but extended class 'Derived' defines it as instance member function.
Related Issues: I didn't find similar issues, although I started by looking for issues requesting for the ability to disable particular errors (TS2425 in this case). There are several (closed) issues in which such an ability is requested or suggested, but I believe the proper solution would be to bring TypeScript in agreement with ES6. After all, it claims to be a superset!
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza reproduciendo el ejemplo en el TypeScript Playground enlazado y sigue la comprobación que informa de TS2425 para una propiedad heredada de tipo any frente a un método de una subclase. Compara esto con la asignación equivalente al prototipo descrita en el issue. Se considera terminado cuando la definición de la clase compila sin TS2425 mientras las comprobaciones de herencia relevantes permanecen intactas.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- typescript
- Área
- compilers
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 35/100