microsoft / microsoft/TypeScript

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

Open
#61,246 0 comments 0 reactions 0 assignees View on GitHub
Domain: Mapped Types Help Wanted Possible Improvement
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

### 🔎 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_

Contributor guide

Open the contributing guide

Research direction

Start with the linked TypeScript Playground reproduction and inspect how the type checker handles the mapped type's `as` clause and conditional constraint. Trace why the constraint on `AcceptNonNullable` is not recognized, then confirm the example no longer reports error 2344 while preserving the filtering behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.