Skip to content

Empty object in ternary operator produces invalid typeΒ #50171

Closed
@olehmisar

Description

@olehmisar

Bug Report

πŸ”Ž Search Terms

empty object, {}, inferred type

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

const x = true ? 'I am a string' : {} // type of `x` is: {}

πŸ™ Actual behavior

Type of x is inferred as {}

πŸ™‚ Expected behavior

Type of x should be inferred as "I am a string" | {}.

For example, if we try this code:

const x = true ? 'I am a string' : 5

...the type of x is inferred as "I am a string" | 5

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions