Microsoft/TypeScript

`x && x` should not be `NonNullable`

Open

#62,133 建立於 2025年7月27日

在 GitHub 查看
 (5 留言) (5 反應) (0 負責人)TypeScript (6,726 fork)batch import
BugDomain: check: Control FlowHelp Wanted

倉庫指標

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

描述

🔎 Search Terms

logical and, generic, NonNullable

🕗 Version & Regression Information

There has been this problem since 4.8.4 (I tried it on the playground)

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/MYewdgzgLgBAZjAvDAPAFQDQD4AUAPALhjQEoksY8YAyaymAegdTV0OLMQoDlxuBXADaCAhgCNBAU3RYAUEA

💻 Code

const f = <T,>(x: T) => x && x // <T>(x: T) => NonNullable<T>

🙁 Actual behavior

Since f returns NonNullable<T>, we can make every value NonNullable, and never can be created by calling f(null).

🙂 Expected behavior

f should return T.

Additional information about the issue

No response

貢獻者指南