-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
$Diff is not compatible with object intersections #3246
Comments
This issue is killing me as well. Is there a working alternate approach that anyone has found? |
This works: type AB = {a: number, b: number};
type A = {a: number};
type B = {b: number};
const x: $Diff<$Diff<AB, A>, B> = {}; I think this should work too: type AB = {a: number, b: number};
type A = {a: number};
type B = {b: number};
const x: $Diff<AB, {...A, ...B}> = {}; But right now object type spread doesn't work in any generic location. |
@rsolomo My workaround has been to manually create the wrapping components for HoCs. The traditional HoC is created using: function withSubscription(WrappedComponent, selectData) {
return class extends React.Component {
render() {
return <WrappedComponent ... />;
}
};
}
class MyComponentImpl extends React.Component {
...
}
MyComponent = withSubscription(MyComponentImpl); The problem is that Instead, I prefer to do this: class MyComponentImpl extends React.Component {
...
}
class WithSubscription extends React.Component {
props: {
render: (InjectedProps) => React$Element<*>,
}
render() {
return this.props.render(injectedProps);
}
}
class MyComponent extends React.Component {
renderWithSubscription(injectedProps) {
return <MyComponnent {...injectedProps} />;
}
render() {
return <WithSubscription />
}
} It's the same thing really, but at the cost of a little verbosity, it reduces all the ambiguity about props and makes using flow a synch. |
I substituted |
This now works |
Gives:
The right half of the union is ignored. This makes certain types of HoCs impossible to type.
The text was updated successfully, but these errors were encountered: