microsoft / microsoft/TypeScript
Variance annotations are not allowed in type aliases for intersections
Open
@ahejlsberg is already working on this.
Since Aug 9, 2024.
Needs Investigation
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔎 Search Terms
variance measurement markers sub sup intersection type aliases
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
💻 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.