Skip to content

Boolean type is not inferred correctly when a variable is declared with let #61727

Closed
@GervinFung

Description

@GervinFung

🔎 Search Terms

boolean

🕗 Version & Regression Information

Seems like this issue is easily reproduced for v3, v4 to v5

I personally had not encounter this issue as I use const when declaring variables almost all the time, might have been an intended design instead?

⏯ Playground Link

https://www.typescriptlang.org/play/?target=99&jsx=0&ts=5.8.3#code/DYUwLgBAhhC8EDMrAM4ggegxAlgOwRACciQATaFCAIgCMB7e0KPagKBi1wONIqirUkqENWgIwxAO5QiZKgApaAV0goAFvWXAKpALZR8lCAyYgW3FJKhkAlGzahItOBADkbzNnyES5Y9RWRPgA5uwuXFY4wMDcvnwBQaHsjuAQAMauAAxecbz+AjR4ynq0xOyZkWDRsT75-ILFpeVAA

💻 Code

let a = false // inferred as "boolean"
a // inferred as "false" afterwards (but should remain as boolean instead)

let b = '' // inferred as "string"
b // still inferred as "string"

let c = 0 // inferred as "number"
c // still inferred as "number"

🙁 Actual behavior

given let a = false

the typeof variable a should be boolean but instead was false

🙂 Expected behavior

given let a = false

the typeof variable a must be boolean, as it's inconsistent with other types such as ''/0 and it's inferred as string/number respectively

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions