microsoft / microsoft/TypeScript
Make AggregateError generic to represent error types
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con le dichiarazioni di AggregateError in lib.es2021.promise.d.ts e lib.es2022.error.d.ts, confrontando gli overload del costruttore esistenti e la proprietà errors con le forme generiche proposte. Verifica che il valore predefinito mantenga l’utilizzo esistente, che i tipi errors inferiti siano rappresentati e che entrambe le dichiarazioni rimangano coerenti.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- tooling
- Tipo di issue
- Funzionalità
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 48/100