Skip to content

2.3.1 TSX spread with union types #15432

@kryops

Description

@kryops

TypeScript Version: 2.3.1, 2.4.0-dev.20170427

Code

type Foo = { foo: string }
type Bar = { bar: string }
type Baz = { baz: string }

type FBB = Foo | Bar | Baz

declare const obj: FBB

const FbbComponent = (props: FBB) => (
    <div>{JSON.stringify(props)}</div>
)

const comp1 = React.createElement(FbbComponent, { ...obj }) // works
const comp2 = <FbbComponent {...obj as Foo} /> // works
const comp3 = <FbbComponent {...obj} /> // does not work

Expected behavior:

Compiles without errors

Actual behavior:
Error:

Type '{}' is not assignable to type '(IntrinsicAttributes & Foo) | (IntrinsicAttributes & Bar) | (IntrinsicAttributes & Baz)'.
  Type '{}' is not assignable to type 'IntrinsicAttributes & Baz'.
    Type '{}' is not assignable to type 'Baz'.
      Property 'baz' is missing in type '{}'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions