microsoft / microsoft/TypeScript
The entries collection in observers should be non-empty
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Go
- Star
- 111k
- Fork
- 14.3k
- Merge trung bình
- 2 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 132
Mô tả
### ⚙ 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.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu từ kiểu ResizeObserverCallback và so sánh các callback liên quan của MutationObserver và IntersectionObserver, sau đó kiểm tra ResizeObserverEntry.contentBoxSize. Sử dụng thuật toán broadcast-active-resize-observations trong Resize Observer specification làm tài liệu tham chiếu; được coi là hoàn tất khi các tập hợp entry này được định kiểu thành các tuple không rỗng mà specification bảo đảm có ít nhất một phần tử.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- typescript
- Lĩnh vực
- frontend
- Loại issue
- Lỗi
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 45/100