react-apollo icon indicating copy to clipboard operation
react-apollo copied to clipboard

Error adding Component state when using graphql wrapper as decorator

Open joeldn opened this issue 9 years ago • 9 comments

Steps to Reproduce

Adding a state type to a React Component class when decorated with the graphql wrapper function.

@graphql<IData, IProps>(query)
class TodoApp extends React.Component<IProps, IState> {
  public render() {
    const { todos } = this.props;
    return (
      <ul>
        {todos.map(({ id, text }) => (
          <li key={id}>{text}</li>
        ))}
      </ul>
    );
  }
}

Buggy Behavior

The newly added type checking breaks my code with a error TS1238: Unable to resolve signature of class decorator when called as an expression. when adding state type, but only if the graphql wrapper function is used as a decorator. With 'normal' wrapping (see below) everything is fine.

const withData = graphql<IData, IProps>(query);

class TodoApp extends React.Component<IProps, IState> {
  public render() {
    const { todos } = this.props;
    return (
      <ul>
        {todos.map(({ id, text }) => (
          <li key={id}>{text}</li>
        ))}
      </ul>
    );
  }
}

const container = withData(TodoApp);

And of course in the initial decorated code, replacing IState with any works (which might be the reason why the tests are succeeding).

ADDITION: I'm also unable to add functions to a react class as it starts complaining: Property 'foo' is missing in type 'Component<IProps, ComponentState>'. Again only when decorating the classes. Am I using this correctly?

Version

joeldn avatar Jun 05 '17 15:06 joeldn

same issue here

OneCyrus avatar Jun 09 '17 18:06 OneCyrus

Is there any update on this? I'm now stuck with using version 1.2.0..

joeldn avatar Jun 23 '17 16:06 joeldn

seeing this as well

joshmadewell avatar Jun 26 '17 00:06 joshmadewell

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions to React Apollo!

stale[bot] avatar Jul 10 '17 01:07 stale[bot]

This issue has been automatically closed because it has not had recent activity after being marked as stale. If you belive this issue is still a problem or should be reopened, please reopen it! Thank you for your contributions to React Apollo!

stale[bot] avatar Jul 17 '17 10:07 stale[bot]

I'm seeing this issue on react-apollo 1.4.8. I'm unable to add any methods or variables to the component class or using a typed state (any-type works as reported above). When doing so I get the error message "Unable to resolve signature of class decorator when called as an expression. ...".

Have anyone got this to work?

So unless I do something wrong the decorator is at the moment unusable. I vote to reopen this issue.

"react": "^15.6.1", "react-apollo": "^1.4.8", "react-dom": "^15.6.1",

samvik avatar Aug 01 '17 08:08 samvik

It's possible to patch original graphql decorator (oversee from mobx-react) but there is need to define additional property (innerProps) for typesafe: https://gist.github.com/mctep/adda5750271f8b0d181e0328e68afb56

mctep avatar Aug 28 '17 09:08 mctep

@samvik same here, using @mctep seems to fix the msg

vcollado avatar Sep 11 '17 08:09 vcollado

same here. decorations make code looks very cleaner. please fix this.

sijad avatar Sep 23 '17 11:09 sijad