The example for `when` doesn't show that it takes the condition value as a parameter

Aperta Adatta ai principianti
#1,480 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@julienw ci sta già lavorando.

Dal 9/7/2026.

  • #1483 di @julienw — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Documentazione
Chiarezza
Specificata chiaramente
Stato di attività
Tranquilla
Stack tecnologico
typescript
Ambito
documentation

Direzione di ricerca

Inizia dalla documentazione della direttiva when collegata nell’issue e confronta il relativo riquadro della firma e l’esempio con l’API v3 descritta qui. Poi esamina lit/packages/lit-html/src/directives/when.ts per individuare l’esempio JSDoc dell’upstream. Il lavoro è completato quando entrambi gli esempi mostrano che il valore della condizione viene passato e la firma nella documentazione riflette correttamente l’API attuale.

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

Descrizione

The when directive docs are out of date with the actual v3 API. Since lit#4310, when() passes the (type-narrowed) condition value to both case functions, but the docs don't reflect this.

1. The Signature box is wrong

It currently shows:

when<T, F>(
  condition: boolean,
  trueCase: () => T,
  falseCase?: () => F
)

The actual v3 signature uses a generic condition and passes it to the callbacks:

when<C, T, F = undefined>(
  condition: C,
  trueCase: (c: Exclude<C, Falsy>) => T,
  falseCase?: (c: Extract<C, Falsy>) => F
): C extends Falsy ? F : T

(We may want to simplify it for the docs? I'm not so sure)

2. The example doesn't use the parameter

It currently is:

${when(this.user, () => html`User: ${this.user.username}`, () => html`Sign In...`)}

It should show the value being passed in (and narrowed), which is the whole point of the feature:

${when(this.user, (user) => html`User: ${user.username}`, () => html`Sign In...`)}
Additional note

The same incomplete example is also in the upstream JSDoc at lit/packages/lit-html/src/directives/when.ts, so that may be worth updating too for consistency.

Lingua principale
TypeScript
Stelle
140
Fork
229
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

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 lit/lit.dev

Tutte le issue di lit/lit.dev

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.