microsoft / microsoft/TypeScript

Assignability between distributive conditional types and their branch type is reversed in contravariant positions

Offen
#63,694 0 Kommentare 0 Reaktionen 1 zugewiesene Person Auf GitHub ansehen

@ahejlsberg arbeitet bereits daran.

Seit 30.7.2026.

Needs Investigation
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
2 T. 4 Std.
Gemergte PRs (30 T.)
132

Beschreibung

### 🔎 Search Terms

"conditional type distribution contravariance" "distributive conditional assignability" "variance conditional types"

### 🕗 Version & Regression Information

- This is the behavior in every version I tried, and I reviewed the FAQ for entries about conditional types, distributive conditional types, and variance

### ⏯ Playground Link

https://www.typescriptlang.org/play/?ts=6.0.3#code/C4TwDgpgBAwg9gNwDwBUB8UC8UDeUBOEAhgCZwB2ANiFAB4BcUKUAvgNwBQokUAIgJYBnYPnjJ0WJlAi1gEciUFSA-LESoMjchAQR8nDgDMAruQDGwfhShzhYjQAoijAcNHr0AGigAjRvfQASlwOKCgAenCoAHkAaX91AEEMISgiQUF+AHNyIh9KaGA4NWREqAAfKAAhNFC0qEEiS0FDfgglALQDMMioAAFgQQBaGUgLEfx8OHwSpDLKmqhU8jhgNIzs3PzC4vtkup8GpqFW9r4hEU7OFg4ucGh4chEiDUkHBiZgzAwEOH4STjcaCuS4UZ6vbDMGRyBRKZiqR7giRaHR6AwmcyWay2YCI-AvdBOFwXdxPfEabx+NRkgloYI4Oq9AbDUYQcZ6KYzPEvZINAAWcGMlBIUBWax80HSmRyeQKNl2YPJ82qtTCRCOzVOHUVtO6ESi3LmFRV-MFwt8ko2Mu28up4P2YUOjU1bSUINJSK6HBYQA

### 💻 Code

```ts
type Cov = { readonly x: T };
type DistrCov = T extends T ? Cov : never;

function testCov(a: DistrCov, b: Cov) {
// OK: Cov is assignable to Cov
a satisfies Cov;

// @ts-expect-error Cov is not assignable to Cov
b satisfies DistrCov;
}

type Contra = (x: T) => void;
type DistrContra = T extends T ? Contra : never;

function testContra(a: DistrContra, b: Contra) {
// @ts-expect-error Contra
should not be assignable to Contra
a satisfies Contra;

// Contra should be assignable to Contra
b satisfies DistrContra;
}
```

### 🙁 Actual behavior

The covariant case behaves as expected.

The contravariant case appears inverted:

- `DistrContra` is accepted as `Contra`, although it should not be.
- `Contra` is rejected as `DistrContra`, although it should be.

### 🙂 Expected behavior

The contravariant case should mirror the covariant one with assignability reversed.

Since conditional distribution over a union produces `Contra | Contra | ...`, it should only be assignable in the contravariant direction.

### Additional information about the issue

_No response_

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.