microsoft / microsoft/TypeScript
T.constructor should be of type T
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
Given
``` typescript
class Example {
}
```
The current type of `Example.constructor` is `Function`, but I feel that it should be `typeof Example` instead. The use case for this is as follows:
I'd like to reference the current value of an overridden static property on the current class.
In TypeScript v1.5-beta, doing this requires:
``` typescript
class Example {
static someProperty = "Hello, world!";
constructor() {
// Output overloaded value of someProperty, if it is overloaded.
console.log(
(this.constructor).someProperty
);
}
}
class SubExample {
static someProperty = "Overloaded! Hello world!";
someMethod() {
console.log(
(this.constructor).someProperty
);
}
}
```
After this proposal, the above block could be shortened to:
``` typescript
class Example {
static someProperty = "Hello, world!";
constructor() {
// Output overloaded value of someProperty, if it is overloaded.
console.log(
this.constructor.someProperty
);
}
}
class SubExample {
static someProperty = "Overloaded! Hello world!";
someMethod() {
console.log(
this.constructor.someProperty
);
}
}
```
This removes a cast to the current class.
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
Use the two class examples in the issue as the behavioral starting point, then trace the TypeScript type-checking rules for instance constructors and static members. Done means the proposed this.constructor accesses type-check without the casts shown, while preserving the intended behavior for subclasses.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- typescript
- Área
- compilers
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Activo
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100