microsoft / microsoft/TypeScript

NodeList should be generic instead of having NodeListOf

オープン
#53,540 コメント 1 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Awaiting More Feedback Suggestion
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

lib Update Request

I may be missing something, but I don't see why NodeListOf exists instead of just having NodeList itself be generic. Maybe it's a vestige from a time before generic parameter defaults.

NodeList should be able to be generic with a default value of Node.

Configuration Check

afaik, this is true of all versions of lib.dom.ts. I've checked up to 5.0

Missing / Incorrect Definition

I think this should be a backwards compatible change:

interface NodeList<TNode extends Node = Node> {
  readonly length: number;
  item(index: number): TNode | null;
  forEach(callbackfn: (value: TNode, key: number, parent: NodeList<TNode>) => void, thisArg?: any): void;
  [index: number]: TNode;
}

/** @deprecated Use NodeList */
interface NodeListOf<TNode extends Node> extends NodeList<TNode> {
  item(index: number): TNode;
}

Sample Code

let getDivs = (): NodeList<HTMLDivElement> => {/* ... */};

Documentation Link

N/A though removing NodeListOf would remove a type that's only present in lid.dom.d.ts, not the actual DOM APIs.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

lib.dom.ts から始めて、NodeList と NodeListOf の宣言を見つけます。要求されたジェネリックのデフォルト値および非推奨の互換性エイリアスと比較します。NodeList が示された HTMLDivElement の使用方法をサポートし、既存の NodeListOf コードが引き続き互換性を保てば、作業は完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
typescript
領域
tooling
issue の種類
リファクタリング
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。