Skip to content

x && x should not be NonNullableΒ #62133

@zeng-y-l

Description

@zeng-y-l

πŸ”Ž 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions