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

オープン 初心者向け
#1,480 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

@julienw がすでに取り組んでいます。

2026年7月9日 から。

  • #1483 @julienw による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
ドキュメント
明瞭さ
明確に書かれている
活発さ
静か
技術スタック
typescript
領域
documentation

調査の方向性

Issue にリンクされている when ディレクティブのドキュメントから始め、その Signature ボックスと例を、ここで説明されている v3 API と比較します。次に、upstream の JSDoc の例を確認するために lit/packages/lit-html/src/directives/when.ts を調べます。両方の例で条件値が渡されていることが示され、ドキュメントのシグネチャが現在の API を正確に反映していれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
TypeScript
スター
140
フォーク
229
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

lit/lit.dev のほかの issue

lit/lit.dev の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。