Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

someBool || true gets the literal type true when assigned to a let variable at initialization (unlike true getting the type boolean)Β #61799

Copy link
Copy link
@aweebit

Description

@aweebit
Issue body actions

πŸ”Ž Search Terms

boolean literal type true false assign expression

πŸ•— Version & Regression Information

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/CYUwxgNghgTiAEEQBd4GcD2BbEAhDGEAXPAEYFJQB2A3AFB1KogAeUWADkgIzwC88ZDACuIek3it2XEACZ+6bHgrwAPqsEixQA

πŸ’» Code

declare let someBool: boolean;

let okay = true;
let weird = someBool || true;

πŸ™ Actual behavior

weird is assigned the type true, whereas okay is of type boolean.

πŸ™‚ Expected behavior

Both variables have the type boolean.

Additional information about the issue

Stumbled upon this while writing react/react#33399.

Very unexpected and confusing behavior, I highly doubt it is intended. Couldn't find anything explaining the change in the release notes for TypeScript 4.2, so pretty sure it's an unwanted regression. Please correct me if I'm wrong.

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Not a DefectThis behavior is one of several equally-correct optionsThis behavior is one of several equally-correct options

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.