Skip to content

Missing properties on union typesΒ #50925

@phm07

Description

@phm07

Bug Report

πŸ”Ž Search Terms

  • union type
  • missing properties

πŸ•— Version & Regression Information

Typescript version: v4.9.0-dev.20220921

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type A = {
    propA: number;
    propB: number;
    propC: number;
    propD: number;
}

type B = {
    propA: number;
    propB: string;
    propC: undefined;
}

type C = A | B;

let test: C;

type TPropA = typeof test.propA; // -> type TPropA = number;
type TPropB = typeof test.propB; // -> type TPropB = string | number;
type TPropC = typeof test.propC; // -> type TPropC = number | undefined;

// TS2551: Property 'propD' does not exist on type 'C'.
type TPropD = typeof test.propD; // -> expected: type TPropD = number | undefined;

πŸ™ Actual behavior

When defining union types of interfaces, properties will be missing on the resulting type if they are missing on one of the original types.

πŸ™‚ Expected behavior

The resulting type should contain the said property, either as an optional or as a union with undefined (-> see TPropC)

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