Skip to content

JSX bug when combining union and intersection types #15355

Closed

Description

TypeScript Versions: 2.2.2, and the 2.3.0 mistakenly released last week

Code

import * as React from 'react';
import { ComponentClass, StatelessComponent } from 'react';

export type ComponentType<P> = ComponentClass<P> | StatelessComponent<P>;

export function withProps<P1, P2>(Component: ComponentType<P1 & P2>, props1: P1) {
  return (props2: P2) => <Component {...props1} {...props2} />;
}

Expected behavior:

Successful compilation.

Actual behavior:

TS2324: Property 'children' is missing in type '(IntrinsicAttributes & IntrinsicClassAttributes<Component<P1 & P2, ComponentState>> & Readonly<{ ...'.

Seems to me that this should be possible, since separate functions for each half of the union type pass the typechecker successfully:

function withProps2<P1, P2>(Component: StatelessComponent<P1 & P2>, props1: P1) {
  return (props2: P2) => <Component {...props1} {...props2} />;
}

function withProps3<P1, P2>(Component: ComponentClass<P1 & P2>, props1: P1) {
  return (props2: P2) => <Component {...props1} {...props2} />;
}

Activity

  1. mhegazy commented on Apr 24, 2017

    @mhegazy
    Contributor

    I am not getting these errors running locally. Can you share a self contained repro?

  2. whatisaphone commented on Apr 25, 2017

    @whatisaphone
    Author

    After digging deeper, it turns out the root cause of my issue is already tracked by #10727 and #13288, so this can be closed. I'll wait for 2.3. Sorry for the noise!

  3. 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.

  4. 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

    Needs More InfoThe issue still hasn't been fully clarified

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions