microsoft / microsoft/TypeScript
Make AggregateError generic to represent error types
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.4k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
lib Update Request
Make it possible for an AggregateError to carry a type parameter representing the shape of the items in its errors array, while preserving backwards compatibility using type parameter defaults.
Specifically, the current definition is:
// In lib.es2021.promise.d.ts
interface AggregateError extends Error {
errors: any[]
}
interface AggregateErrorConstructor {
new(errors: Iterable<any>, message?: string): AggregateError;
(errors: Iterable<any>, message?: string): AggregateError;
readonly prototype: AggregateError;
}
// In lib.es2022.error.d.ts; adds `options` argument.
interface AggregateErrorConstructor {
new (
errors: Iterable<any>,
message?: string,
options?: ErrorOptions
): AggregateError;
(
errors: Iterable<any>,
message?: string,
options?: ErrorOptions
): AggregateError;
}
I'm proposing instead:
// In lib.es2021.promise.d.ts
interface AggregateError<T = any> extends Error {
errors: T[]
}
interface AggregateErrorConstructor {
new<T = any>(errors: Iterable<T>, message?: string): AggregateError<T>;
<T = any>(errors: Iterable<T>, message?: string): AggregateError<T>;
readonly prototype: AggregateError;
}
// In lib.es2022.error.d.ts
interface AggregateErrorConstructor {
new<T = any>(errors: Iterable<T>, message?: string,
options?: ErrorOptions): AggregateError<T>;
<T = any>(errors: Iterable<T>, message?: string,
options?: ErrorOptions): AggregateError<T>;
readonly prototype: AggregateError;
}
Again, the only difference is the addition of a new T parameter defaulting to any (the old value), with the errors key updated from any[] to T[].
Configuration Check
My compilation target is ES2022 and my lib is ["ES2022", "DOM"].
Missing / Incorrect Definition
NA, as the property isn't missing; it's just underspecified.
I think this would be a nice quality of life improvement, esp for code that returns AggregateErrors (sorta analogous to the functional style of returning a Result type) rather than throwing them.
Sample Code
// Current
const x = new AggregateError([new Error("Something something...")]).errors; // type is any[]
// With proposal
const x = new AggregateError([new Error("Something something...")]).errors // type is Error[]
Documentation Link
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 con las declaraciones de AggregateError en lib.es2021.promise.d.ts y lib.es2022.error.d.ts, comparando las sobrecargas de constructor existentes y la propiedad errors con las formas genéricas propuestas. Verifica que el valor predeterminado conserve el uso existente, que se representen los tipos errors inferidos y que ambas declaraciones sigan siendo coherentes.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- typescript
- Área
- tooling
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 48/100