microsoft / microsoft/TypeScript
Make AggregateError generic to represent error types
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
lib.es2021.promise.d.ts と lib.es2022.error.d.ts の AggregateError 宣言から始め、既存のコンストラクターオーバーロードと errors プロパティを、提案されているジェネリック形式と比較します。デフォルトが既存の使用方法を維持すること、推論された errors 型が表現されること、そして両方の宣言の整合性が保たれることを確認してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- tooling
- issue の種類
- 機能追加
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 48/100