Skip to content
This repository has been archived by the owner on Dec 31, 2020. It is now read-only.

Typings on inject #323

Closed
tomitrescak opened this issue Sep 11, 2017 · 2 comments
Closed

Typings on inject #323

tomitrescak opened this issue Sep 11, 2017 · 2 comments

Comments

@tomitrescak
Copy link

tomitrescak commented Sep 11, 2017

Hi, the typings on inject are a bit off.
I have Component with props { foo: string };
Then I will perform mapping:

type ContainerProps = {
  bar: number
}
type ComponentProps = {
  foo: string
}

const Composed = inject<ComponentProps, ContainerProps>((stores, props) => 
    ({ foo: stores.some[props.bar]}))(Component);

The problem is that the returning component has props of type ComponentProps. so, when I try to use this component:

<Composed bar={4}  />

I get error that foo parameter is missing. That's obviously incorrect, as the composed component should only receive bar.

@tomitrescak
Copy link
Author

tomitrescak commented Sep 11, 2017

Looking at the definition:

export function inject<P>(...stores: string[]): (<TFunction extends IReactComponent<P>>(target: TFunction) => (TFunction & IWrappedComponent<P>)); // decorator signature
export function inject<T, P>(storesToProps : IStoresToProps<T, P>): (<TFunction extends IReactComponent<T | P>>(target: TFunction) => (TFunction & IWrappedComponent<P>)); // decorator

This did the trick

export function inject<P>(...stores: string[]): (<TFunction extends IReactComponent<P>>(target: TFunction) => (IReactComponent<P>)); // decorator signature
export function inject<T, P>(storesToProps : IStoresToProps<T, P>): (<TFunction extends IReactComponent<T | P>>(target: TFunction) => (IReactComponent<P>)); // decorator

Not sure if it is what you meant, but in my opinion, it is more correct. But I'm probably wrong here ;) What is the reasoning of the returning component also having props of the wrapped component?

EDIT: No, the proposed solution explodes when used with regular components

@mweststrate
Copy link
Member

I think this is a duplicate of #256 ?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants