microsoft / microsoft/TypeScript

Unexpected distributive behaviour on type alias

Đang mở
#62,761 6 bình luận 1 reaction 1 người được giao Xem trên GitHub

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

Từ ngày 17/11/2025.

Needs Investigation
Ngôn ngữ chính
Go
Star
111k
Fork
14.3k
Merge trung bình
2 ngày 4 giờ
Pull request đã merge (30 ngày)
132

Mô tả

🔎 Search Terms

distributive conditional types, naked type parameter, type alias, unions

🕗 Version & Regression Information
  • This changed between versions 3.8.3 and 3.9.7.
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about distributive conditional types, naked type parameter, type alias, unions.
⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.9.3#code/C4TwDgpgBAaghgGwK7QLxQIxQD5QEwBQBokUAKhALZhToDa8yEAulBAB7AQB2AJgM5Q6AS24AzCACdYzAlCgB+WG048BUJNwDW3APYB3bnPmKhMADSxEKWSagAuKNwgA3KccfO3koiWgAlCH4kBGBacioaAHoolUgAYzC6DEssXDxWXDo8VJx8WxMYgD0FIA

💻 Code
type Value = 1 | 2

type Result = [Value] extends [infer V]
  ? V extends unknown
    ? [V, Value]
    : never
  : never
🙁 Actual behavior
[1, 1] | [2, 2]
🙂 Expected behavior
[1, 1 | 2] | [2, 1 | 2]
Additional information about the issue

It shouldn't work the way it does now, for several reasons:

  1. Value is not naked type parameter.
  2. Using brackets, distributive behaviour must be disabled.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

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.

Đánh giá

Issue này chưa được đánh giá.

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.