microsoft / microsoft/TypeScript
The entries collection in observers should be non-empty
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.3k
- Merge medio
- 2 d 4 h
- PR fusionados (30 d)
- 132
Descripción
⚙ 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
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.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con el tipo ResizeObserverCallback y compara los callbacks relacionados de MutationObserver e IntersectionObserver; después, inspecciona ResizeObserverEntry.contentBoxSize. Usa el algoritmo broadcast-active-resize-observations de la Resize Observer specification como referencia; se considera terminado cuando estas colecciones de entradas están tipadas como tuplas no vacías para las que la especificación garantiza al menos un elemento.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- typescript
- Área
- frontend
- Tipo de issue
- Error
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 45/100