microsoft / microsoft/TypeScript

The entries collection in observers should be non-empty

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

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

Experience Enhancement Help Wanted Suggestion
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
2日 4時間
マージ済み PR(30日)
132

説明

### ⚙ Compilation target

ES2017

### ⚙ Library

TypeScript

### Missing / Incorrect Definition

The type in question is `ResizeObserverCallback`, and similar observer callbacks, like the ones in `MutationObserver` and `IntersectionObserver`. These currently accept entries in the `T[]` format, but it should really be `[T, ...T[]]`. This is because the observer callback is only ever invoked when there is at least one entry.

(I've also noticed the same issue with the `ResizeObserverEntry`'s `contentBoxSize` property.)

### Sample Code

```TypeScript
const ro = new ResizeObserver(entries => {
const entry = entries[0] // <-- This should never be undefined
const size = entry.contentBoxSize[0] // <-- Nor this, btw
const dim = size.blockSize
console.log(dim / 2)
})
```

### Documentation Link

While there is no direct verbiage that suggests the entry collection is never empty, it stems from the description of the algorithms. For example in case of the `ResizeObserver`:

https://drafts.csswg.org/resize-observer/#broadcast-active-resize-observations

The observer callback is never invoked if there are no observations. Otherwise, entries are created for each observation. This pretty much guarantees the entries collection is non-empty.

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

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

はじめの一歩

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

調査の方向性

ResizeObserverCallback型から始め、関連するMutationObserverとIntersectionObserverのコールバックを比較し、続いてResizeObserverEntry.contentBoxSizeを確認します。Resize Observer specificationのbroadcast-active-resize-observationsアルゴリズムを参照とし、仕様によって少なくとも1つの項目が保証されているこれらのエントリコレクションが、空でないタプルとして型付けされれば完了です。

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

評価

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

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

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