React-apollo: graphql typescript decorator

Created on 30 Sep 2017  路  4Comments  路  Source: apollographql/react-apollo

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

Most helpful comment

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.

All 4 comments

I came across this as well.

It appears to be a limitation in how TypeScript handles "contextual types": https://github.com/Microsoft/TypeScript/issues/19212

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.

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!

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

Was this page helpful?
0 / 5 - 0 ratings