microsoft / microsoft/TypeScript

The entries collection in observers should be non-empty

Aperta
#61,691 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Experience Enhancement Help Wanted Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

⚙ 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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia dal tipo ResizeObserverCallback e confronta i callback correlati di MutationObserver e IntersectionObserver, quindi esamina ResizeObserverEntry.contentBoxSize. Usa l’algoritmo broadcast-active-resize-observations della Resize Observer specification come riferimento; il lavoro è completato quando queste raccolte di entry sono tipizzate come tuple non vuote per le quali la specifica garantisce almeno un elemento.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
frontend
Tipo di issue
Bug
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.