microsoft / microsoft/TypeScript
The entries collection in observers should be non-empty
还没有人认领这个 Issue。
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 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.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 ResizeObserverCallback 类型开始,比较相关的 MutationObserver 和 IntersectionObserver 回调,然后检查 ResizeObserverEntry.contentBoxSize。以 Resize Observer specification 的 broadcast-active-resize-observations 算法为参考;当这些条目集合被类型化为非空元组,且规范保证其中至少有一个条目时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript
- 领域
- frontend
- Issue 类型
- 缺陷
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 45/100