Variance annotations are not allowed in type aliases for intersections

Aberta
#59,561 5 comentários 2 reações 1 responsável Ver no GitHub

@ahejlsberg já está trabalhando nisso.

Desde 9/8/2024.

Avaliação

Esta issue ainda não foi avaliada.

Descrição

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

Linguagem predominante
Go
Estrelas
111k
Forks
14.4k
Merge médio
1d 19h
PRs com merge (30d)
117

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de microsoft/TypeScript

Todas as issues de microsoft/TypeScript

Issues semelhantes

Mais issues de Go

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.