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

Đang mở Phù hợp với người mới
#1,480 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

@julienw đang làm issue này rồi.

Từ ngày 9/7/2026.

  • #1483 của @julienw — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/100
Loại issue
Tài liệu
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
typescript
Lĩnh vực
documentation

Hướng nghiên cứu

Bắt đầu với tài liệu về directive when được liên kết trong issue và so sánh ô Signature cùng ví dụ của tài liệu đó với API v3 được mô tả ở đây. Sau đó, kiểm tra lit/packages/lit-html/src/directives/when.ts để tìm ví dụ JSDoc từ upstream. Được xem là hoàn tất khi cả hai ví dụ đều thể hiện việc truyền giá trị điều kiện và chữ ký trong tài liệu phản ánh chính xác API hiện tại.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
TypeScript
Star
140
Fork
229
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của lit/lit.dev

Tất cả issue của lit/lit.dev

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.