Microsoft/TypeScript

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

Open

#61,246 建立於 2025年2月22日

在 GitHub 查看
 (0 留言) (0 反應) (0 負責人)TypeScript (6,726 fork)batch import
Domain: Mapped TypesHelp WantedPossible Improvement

倉庫指標

Star
 (48,455 star)
PR 合併指標
 (平均合併 6天 17小時) (30 天內合併 9 個 PR)

描述

🔎 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

type AcceptNonNullable<T extends {}> = T;

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

🙁 Actual behavior

AcceptNonNullable<T[K]> 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

貢獻者指南