Skip to content

$Diff with ...rest doesn't work #3541

Description

@sepo-one

Example:

/* @flow */

type Props = {
	title: string;
  	age: number;
};

type WrapProps = $Diff<Props, {
	age: number;
}>;

const Person = (props: Props) => {};
const YoungPerson = (props: WrapProps) => {
	return Person({age: 21, ...props});
};

Gives an error:

14: 	return Person({age: 21, ...props});
                   ^ object literal. Expected object instead of
14: 	return Person({age: 21, ...props});
                                ^ Props

However if i declare WrapProps sub type manually, it works:

/* @flow */

type Props = {
	title: string;
  	age: number;
};

/*type WrapProps = $Diff<Props, {
	age: number;
}>;
*/

type WrapProps = {
	title: string;
};

const Person = (props: Props) => {};
const YoungPerson = (props: WrapProps) => {
	return Person({age: 21, ...props});
};

Seems like $Diff is not working correctly.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions