Skip to content

Type union collapses into the general type in conditionΒ #55158

Closed
@FlandreDaisuki

Description

@FlandreDaisuki

Bug Report

πŸ”Ž Search Terms

type union collapses

πŸ•— Version & Regression Information

  • I've tried from 3.3.3 to 5.2.0-beta and the result are the same.

⏯ Playground Link

Playground link

πŸ’» Code

const a = (Math.random() > 0.5)
  ? Object.freeze({ok: false, hello: 'world'})
  : Object.freeze({ok: false});

πŸ™ Actual behavior

type A = typeof a;
//   ^? shows type A = {readonly ok: false}

πŸ™‚ Expected behavior

type A = typeof a;
//   ^? shows type A = Readonly<{ok: false}> | Readonly<{ok: false, hello: 'world'}>

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