lit / lit/lit.dev

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

Open Beginner friendly
#1,480 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
142
Forks
230
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the when directive documentation linked in the issue and compare its Signature box and example with the v3 API described here. Then inspect lit/packages/lit-html/src/directives/when.ts for the upstream JSDoc example. Done means both examples show the condition value being passed and the documentation signature accurately reflects the current API.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.