Skip to content

Remove state from React.FC type definition. #178

Merged
developit merged 1 commit intodevelopit:masterfrom
dan-lee:patch-1
Nov 5, 2019
Merged

Remove state from React.FC type definition. #178
developit merged 1 commit intodevelopit:masterfrom
dan-lee:patch-1

Conversation

@dan-lee
Copy link
Contributor

@dan-lee dan-lee commented Oct 30, 2019

Fixes #177

Copy link
Owner

@developit developit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks.

@developit developit merged commit 9e80737 into developit:master Nov 5, 2019
@developit
Copy link
Owner

Released as Unistore 4.5.1 - thanks.

@dan-lee
Copy link
Contributor Author

dan-lee commented Nov 6, 2019

Thank you @developit 🎉

@dan-lee dan-lee deleted the patch-1 branch November 6, 2019 08:30
@eduardoborges
Copy link
Contributor

eduardoborges commented Nov 25, 2019

But...

/Users/eduardoborges/Projetos/react-dudu-starter/src/screens/welcome/index.tsx
TypeScript error in /Users/eduardoborges/Projetos/react-dudu-starter/src/screens/welcome/index.tsx(56,46):
Argument of type 'FC<Props>' is not assignable to parameter of type '((props: unknown) => ReactNode) | ComponentClass<unknown, unknown> | FC<unknown>'.
  Type 'FC<Props>' is not assignable to type 'FC<unknown>'.
    Types of parameters 'props' and 'props' are incompatible.
      Type '{ children?: ReactNode; }' is not assignable to type 'PropsWithChildren<Props>'.
        Property 'TODOS' is missing in type '{ children?: ReactNode; }' but required in type 'StateProps'.  TS2345

    54 | 
    55 | 
  > 56 | export default connect('TODOS', todoActions)(Login);
       |                                              ^
    57 | 

My code:

import { RouteComponentProps } from '@reach/router';
import { connect } from 'unistore/react';
import { TodoState, TodoActions } from 'store/todo/types';
import todoActions from 'store/todo/actions';

interface StateProps {
  TODOS: TodoState
}
interface OwnProps {
  bar?:boolean
}

type Props = StateProps & TodoActions & OwnProps & RouteComponentProps;

const MyScreen : React.FC<Props> = (props) => {
  return (
      ...
  );
};

export default connect('TODOS', todoActions)(MyScreen);

@38elements
Copy link
Contributor

It seems that Generics of connect() is required.

unistore/react.d.ts

Lines 10 to 15 in b08e0c5

export function connect<T, S, K, I>(
mapStateToProps: string | Array<string> | StateMapper<T, K, I>,
actions?: ActionCreator<K> | object
): (
Child: ((props: T & I) => React.ReactNode) | React.ComponentClass<T & I, S> | React.FC<T & I>
) => React.ComponentClass<T | T & I, S> | React.FC<T | T & I>;

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

React type error: Generic type 'FC' requires between 0 and 1 type arguments.

4 participants