Skip to content

Discriminated Unions with a common partially optional propertyΒ #44689

Closed
@nmalyschkin

Description

@nmalyschkin

Bug Report

πŸ”Ž Search Terms

Discriminated Unions with a common partially optional property

πŸ•— Version & Regression Information

  • I tried different versions of 3 and 4.

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

interface B {
  a: true;
  b: number;
}
interface C {
  a?: false;
  c: number;
}
type Union = B | C;

const test1: Union = {
  a: false,
  c: 5,
};
const test2: Union = {
  c: 4,
};
const test3: Union = {
  a: true,
  b: 4,
};
const test4: Union = {
  b: 4,
  c: 4,
};

πŸ™ Actual behavior

test4 is displayed as valid.

πŸ™‚ Expected behavior

test4 should not be valid.

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