[Web API type definition issue] Mark navigator.serviceWorker as an optional property

Aperta
#1,987 8 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

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

Direzione di ricerca

Nell’issue non sono indicati né un file sorgente né un test. Inizia esaminando come il generatore rappresenta Navigator e ServiceWorker, quindi leggi l’issue TypeScript collegata e la discussione esistente prima di modificare la dichiarazione. Il lavoro è completato quando il tipo generato riflette il comportamento opzionale segnalato e la validazione pertinente va a buon fine.

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

Descrizione

lib.d.ts bug
Summary

navigator.serviceWorker may be undefined in some secure contexts, like IABs and Firefox Private Mode

Expected vs. Actual Behavior
navigator.serviceWorker.register()

Expected: throw a TypeScript error; serviceWorker may be undefined
Actual: no TypeScript error

Playground Link

No response

Browser Support
  • This API is supported in at least two major browser engines (not two Chromium-based browsers).
Have Tried The Latest Releases
  • This issue applies to the latest release of TypeScript.
  • This issue applies to the latest release of @types/web.
Additional Context

I am requesting a reconsideration of marking navigator.serviceWorker as optional.

The previous issue opened in 2023 on the TypeScript repository has been labeled as "Working as Intended" under the explanation by Ryan Cavanaugh: (https://github.com/microsoft/TypeScript/issues/52044#issuecomment-1372844081)

Quoting:

APIs like these are marked non-optional for convenience, since it's extremely plausible that your script runs only in secure contexts as an invariant.

Based on his comment, it appears to me that it had been misunderstood that serviceWorker is undefined in non-secure contexts, while the point is that it may be undefined even in secure contexts.

Examples include but are not limited to:

  • Firefox's private mode
  • Some in-app browsers, especially those on iOS.

In-app browser usage is not insignificant!

~62% of global web traffic comes from mobile devices, and, according to eMarketer, ~88% of the time people spend in their mobile devices is used on apps. Apps today incorporate IABs for the purposes of authentication, advertisement, and more. IAB usage is at its peak in social media and messaging apps.

Given the high usage of IABs. serviceWorker not being an optional property of navigator is anything but convenient.

Lingua principale
TypeScript
Stelle
740
Fork
474
Merge medio
2g 8h
PR unite (30g)
15

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

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.

Altre issue di microsoft/TypeScript-DOM-lib-generator

Tutte le issue di microsoft/TypeScript-DOM-lib-generator

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.