microsoft / microsoft/TypeScript
Allow type narrowing for arrays using Array#forEach and assertion function
オープン
まだ誰も着手していません。
Awaiting More Feedback
Suggestion
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
lib Update Request
Configuration Check
My compilation target is ES5 and my lib is the default.
Missing / Incorrect Definition
Array type narrowing using Array#forEach with assertion function, in a fashion similar to Array#every, has not been defined. Also applies to ReadonlyArray.
Sample Code
const foo: (number | string)[] = ['aaa'];
function assertString(x: unknown): asserts x is string {
if (typeof x !== 'string') throw new Error('Must be a string!');
}
foo.forEach(assertString);
foo[0].slice(0); // foo should be string[] from here
Documentation Link
Based on Array#every<S extends T> from lib.es5.d.ts.
A pull request for implementing this definition has been created #52388.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
lib/lib.es5.d.ts から始め、既存の Array#every の定義を参照してください。提供されたアサーション関数の例に照らして、Array と ReadonlyArray の forEach 宣言を確認してください。完了の条件は、例によって forEach の後に配列要素の型がエラーなしで絞り込まれ、可変配列と readonly 配列の両方が対象になっていることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 20/100