Skip to content

Intersection Type not merging objects in array properlyΒ #52073

Closed
@ErlendS

Description

@ErlendS

Bug Report

πŸ”Ž Search Terms

intersection type, intersection type array

πŸ•— Version & Regression Information

  • This changed between versions 4.8.4 and 4.9.4
  • This bug also appears in version 3.5.1, 3.3.3

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

interface Colorful {
  color: string;
}
interface Circle {
  radius: number;
}

type ColorfulCircle = Colorful[] & Circle[];

const test: ColorfulCircle = [{
  color: 'red',
  radius: 2
}]

πŸ™ Actual behavior

radius field gets type error: Object literal may only specify known properties, and 'radius' does not exist in type 'Colorful'

It looks like it is treating it as a union type where only one of the fields can exist.

πŸ™‚ Expected behavior

I expected the merging of the types to make color and radius accessible (and required) in the ColorfulCircle type.

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