Variance annotations are not allowed in type aliases for intersections

Đang mở
#59,561 5 bình luận 2 reaction 1 người được giao Xem trên GitHub

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

Từ ngày 9/8/2024.

Đánh giá

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

Mô tả

Needs Investigation
🔎 Search Terms

variance measurement markers sub sup intersection type aliases

🕗 Version & Regression Information
  • This is the behavior in every version I tried
⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.6.0-dev.20240808#code/C4TwDgpgBAKgYgewQHgGoEMA2BXCA+KAXigG8oFtgAuKDHaAXwG4AoUSWAIXQCc0tcBYmQCWAOxoAKXgHMadXAEoiBAG4IRAEyjM24aDG4AvZOPKVaA-EViIUC6wDIuvfvTysgA

💻 Code
interface Foo<Value> {
  out: Value;
}
interface Bar<Value> {
  in: (arg: Value) => void;
}

// }
interface Foo<Value> {
  out: Value;
}
interface Bar<Value> {
  in: (arg: Value) => void;
}

type Baz<in out Value> = Foo<Value> & Bar<Value>;

type First<in out Value> = Foo<Value>;
type Second<in out Value> = Bar<Value>;

// Variance annotations are only supported in type aliases for object, function, constructor, and mapped types.(2637)
type Baz<in out Value> = Foo<Value> & Bar<Value>;

// both members are allowed to have annotations
type First<in out Value> = Foo<Value>;
type Second<in out Value> = Bar<Value>;
🙁 Actual behavior

Error is raised

🙂 Expected behavior

I'd expect this to work, especially since https://github.com/microsoft/TypeScript/pull/56418 allowed it to work on more types. Note that this issue isn't even strictly related to using generic references as constituent members. The same issue happens with type aliases and interfaces

Additional information about the issue

Maybe this is expected but I couldn't quickly find any issue related to it or an explicit mention of intersections being purposefully disallowed here

Ngôn ngữ chính
Go
Star
111k
Fork
14.4k
Merge trung bình
1 ngày 19 giờ
Pull request đã merge (30 ngày)
117

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.

Issue khác của microsoft/TypeScript

Tất cả issue của microsoft/TypeScript

Issue tương tự

Thêm issue về Go

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.