Skip to content

2.3.1 TSX spread with union types #15432

Closed

Description

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 '{}'.

Activity

  1. mhegazy commented on Apr 28, 2017

    @mhegazy
    Contributor

    This is a duplicate of #14112, #15420, #13557, and #14409 fixed by #13288.

  2. mhegazy commented on May 19, 2017

    @mhegazy
    Contributor

    Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

  3. locked and limited conversation to collaborators on Jun 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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