Skip to content
This repository has been archived by the owner on Jul 10, 2019. It is now read-only.

graphql typescript decorator #47

Closed
jbaxleyiii opened this issue Nov 13, 2017 · 3 comments
Closed

graphql typescript decorator #47

jbaxleyiii opened this issue Nov 13, 2017 · 3 comments

Comments

@jbaxleyiii
Copy link
Contributor

Intended outcome:
If add a any method except render() typescript begins to resent

Actual outcome:

Only render() method
default

With any method
2

And error occurs when render method return type only JSX.Element with out "false"
3

React works normally in all cases

How to reproduce the issue:
Repair typescript types

Version

  • apollo-client@1.4.16
  • react-apollo@1.9.3
@jbaxleyiii
Copy link
Contributor Author

➤ Jim Kynde Meyer commented:

I came across this as well.

It appears to be a limitation in how TypeScript handles "contextual types": microsoft/TypeScript#19212

@jbaxleyiii
Copy link
Contributor Author

➤ Jim Kynde Meyer commented:

For anyone else running into this, here's a workaound:

I've redefined the graphql decorator with the return type as any. It simply invokes the original graphql decorator.

import {graphql as __graphql, OperationOption} from 'react-apollo';

export function graphql<TProps, TResult>(gqlQuery, operationOptions?: OperationOption<TProps, TResult>): any {
return __graphql(gqlQuery, operationOptions);
}Import the @graphql decorator you defined and the TS compiler will no longer complain about the render() method having an incompatible type.

@jbaxleyiii
Copy link
Contributor Author

➤ stale[bot] commented:

This issue has been automatically labled because it has not had recent activity. If you have not received a response from anyone, please mention the repository maintainer (most likely @jbaxleyiii). It will be closed if no further activity occurs. Thank you for your contributions to React Apollo!

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

1 participant