microsoft / microsoft/TypeScript
Array inheritance in ES6 declaration file (lib.es6.d.ts)
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
ES6 supports Array inheritance, but this is not reflected in the TypeScript declaration file (lib.es6.d.ts).
Array functions like 'filter' and 'slice' return an array of the subclass, so the following should compile in TypeScript:
class MyArray extends Array {
get size() { return this.length; }
}
var x = new MyArray(10).slice();
x.size;
The functions 'reverse', 'concat', 'slice', 'splice', 'filter' should return with the type 'this'.
The 'map' function returns an instance of the subtype too, but it I don't know how that could be represented in TypeScript, as it would require a generic parameter in the return type, something like:
map<U>(callback: (value: T, index: number, array: this) => U): this<U>
Another issue is the static constructors of the Array class, this should compile too:
var x = MyArray.of(1,2,3);
var y = MyArray.from([1,2,3]);
x.size;
y.size;
There are also some additional complications added by the @@species Symbol, which can be used to change the type signature of the subclass to not use 'this' as the return value for functions like 'filter' and 'slice'. So for the following example, the subclass would work how the return types are defined in the declaration file currently:
class MyArray2 extends Array {
static get [Symbol.species]() { return Array; }
}
Chrome and Node.js both already implement the array inheritance features shown here.
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 en lib.es6.d.ts e inspecciona las declaraciones de los métodos de Array y de los constructores estáticos comparándolas con los ejemplos del issue. Determina cómo deberían representar los tipos de retorno la herencia de clases, map y Symbol.species, y verifica que los casos proporcionados MyArray y MyArray2 se compilen como se espera.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- javascript, typescript
- Área
- compilers
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100