microsoft / microsoft/TypeScript

Conditional type flow types missing in the template in mapped types with as clause

Offen
#61,246 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Domain: Mapped Types Help Wanted Possible Improvement
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
2 T. 4 Std.
Gemergte PRs (30 T.)
132

Beschreibung

### 🔎 Search Terms

as clause renaming filtering mapped type conditional type flow

### 🕗 Version & Regression Information

- This is the behavior in every version I tried

### ⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.9.0-dev.20250222#code/C4TwDgpgBAggxnCZgDkD2A7FBXANrgQwCNcIAeAFSggA9gIMATAZygG8BfAPigF4oKAbgBQw0JAERmwSj35thUKAG0A0lACWGKAGsIINADMBUAqwpqAutToMW7DlAD8UdQC4oGCADcIAJ0sPeERkdCw8QhJyC1VLLhEOESA

### 💻 Code

```ts
type AcceptNonNullable = T;

type Test = {
[K in keyof T as T[K] extends {} ? K : never]: AcceptNonNullable;
};
```

### 🙁 Actual behavior

`AcceptNonNullable` errors with:
```
Type 'T[K]' does not satisfy the constraint '{}'.
Type 'T[keyof T]' is not assignable to type '{}'.
Type 'T[string] | T[number] | T[symbol]' is not assignable to type '{}'.
Type 'T[string]' is not assignable to type '{}'.(2344)
```

### 🙂 Expected behavior

It doesn't have to error. It's known that `T[K]` has to extend `{}` at this position

### 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.

Rechercherichtung

Beginnen Sie mit der verlinkten TypeScript Playground-Reproduktion und untersuchen Sie, wie der Type Checker die `as`-Klausel und die bedingte Constraint des gemappten Typs verarbeitet. Verfolgen Sie, warum die Constraint für `AcceptNonNullable` nicht erkannt wird, und bestätigen Sie anschließend, dass das Beispiel nicht mehr den Fehler 2344 meldet, während das Filterverhalten erhalten bleibt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
compilers
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
38/100

Neue Issues direkt in Ihr Postfach

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