Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type definitions for react-relay don't seem to be accurate anymore #18676

Closed
4 tasks done
justinlevi opened this issue Aug 6, 2017 · 4 comments
Closed
4 tasks done

Type definitions for react-relay don't seem to be accurate anymore #18676

justinlevi opened this issue Aug 6, 2017 · 4 comments

Comments

@justinlevi
Copy link

justinlevi commented Aug 6, 2017

Seeing this error with the latest version of relay and the latest typings
screen shot 2017-08-06 at 5 17 35 pm

Given the following package.json:

"dependencies": {
    "@types/jest": "^20.0.6",
    "@types/node": "^8.0.19",
    "@types/react": "^16.0.0",
    "@types/react-dom": "^15.5.2",
    "@types/react-relay": "^0.9.13",
    "babel-relay-plugin": "^0.9.*",
    "babel-plugin-relay": "1.2.0-rc.1",
    "prop-types": "^15.5.10",
    "react": "^15.6.1",
    "react-dom": "^15.6.1",
    "react-relay": "1.2.0-rc.1"
  },

The following class, taken directly from the react-relay-tests.tsx will throw an error when you try to instantiate it.

import * as Relay from 'react-relay';

interface Props {
  text: string;
  userId: string;
}

interface State {
}

export default class AddTweetMutation extends Relay.Mutation<Props, State> {

  public getMutation() {
    return Relay.QL`mutation{addTweet}`;
  }

  public getFatQuery() {
    return Relay.QL`
            fragment on AddTweetPayload {
                tweetEdge
                user
            }
        `;
  }

  public getConfigs() {
    return [{
      type: 'RANGE_ADD',
      parentName: 'user',
      parentID: this.props.userId,
      connectionName: 'tweets',
      edgeName: 'tweetEdge',
      rangeBehaviors: {
        '': 'append',
      },
    }];
  }

  public getVariables() {
    return this.props;
  }
}
@justinlevi
Copy link
Author

Also, just to note that using any version of react-relay after 0.9.x seems to have the same error for me.

Here's a simple project for reference.
https://github.com/justinlevi/HelloWorldTypescriptReactRelay

@voxmatt
Copy link
Contributor

voxmatt commented Aug 7, 2017

Yeah, the type-defs are no longer accurate post Relay 1.0.

On our project, we've copy/pasted the types and put them under react-relay/classic — the pre-1.0 types are basically 1:1 with what's in classic now. Unfortunately, building out types for modern is a big undertaking.

@justinlevi
Copy link
Author

justinlevi commented Aug 7, 2017

@voxmatt thanks for the note. I can confirm that I can use the classic typings by copying the node_modules/@types/react-relay folder into <app root>/custom_typings/react-relay/classic and then adding the typeRoots key to mytsconfig.json

...
  "typeRoots": [
    "custom_typings",
    "node_modules/@types"
  ]

then importing via:

import * as Relay from 'react-relay/classic';

@alloy
Copy link
Collaborator

alloy commented Oct 24, 2017

This should now work with the typings for Relay v1 as well.

@alloy alloy closed this as completed Oct 24, 2017
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

No branches or pull requests

3 participants