Microsoft/TypeScript

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

Open

#62.133 geöffnet am 27. Juli 2025

Auf GitHub ansehen
 (5 Kommentare) (5 Reaktionen) (0 zugewiesene Personen)TypeScript (6.726 Forks)batch import
BugDomain: check: Control FlowHelp Wanted

Repository-Metriken

Stars
 (48.455 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 6T 17h) (9 gemergte PRs in 30 T)

Beschreibung

🔎 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

Contributor Guide