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

Error when compiling Typescript example from Docs #3462

Closed
tomitrescak opened this issue May 16, 2018 · 1 comment
Closed

Error when compiling Typescript example from Docs #3462

tomitrescak opened this issue May 16, 2018 · 1 comment

Comments

@tomitrescak
Copy link

I am trying the Typescript example from Docs

receive:

Type 'undefined' is not assignable to type ...

How to reproduce the issue:

tsconfig.json

{
  "compilerOptions": {
    "target": "esnext",
    "module": "commonjs",
    "moduleResolution": "node",
    "lib": ["es2017", "dom"],
    "jsx": "react",
    "baseUrl": "./src",
    "noEmit": true,
    "skipLibCheck": true,
    "pretty": true,
    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
  }
}

Example from https://www.apollographql.com/docs/react/recipes/static-typing.html

import React from "react";
import gql from "graphql-tag";
import { graphql } from "react-apollo";

const HERO_QUERY = gql`
  query GetCharacter($episode: Episode!) {
    hero(episode: $episode) {
      name
      id
      friends {
        name
        id
        appearsIn
      }
    }
  }
`;

type Hero = {
  name: string;
  id: string;
  appearsIn: string[];
  friends: Hero[];
};

type Response = {
  hero: Hero;
};

type Variables = {
  episode: string;
};

// note the first parameter is empty here, we will exaplain that below
const withCharacter = graphql<{}, Response, Variables>(HERO_QUERY, {
  options: () => ({
    variables: { episode: "JEDI" }
  })
});

export default withCharacter(({ data: { loading, hero, error } }) => {
  if (loading) return <div>Loading</div>;
  if (error) return <h1>ERROR</h1>;
  return ...// actual component with data;
});

When disabling the strictNullChecks another error appears.

Version

  • apollo-client@2.3.1
@ghost ghost added the has-reproduction label May 16, 2018
@hwillson
Copy link
Member

If you're able to share a reproduction that outlines what you've tried, and what isn't working, that would definitely help with troubleshooting. That code sample isn't complete, so it's a bit difficult to pinpoint the problem you're encountering (e.g. return ... is invalid). I'll close this for now, but if you're able to share your code, let us know - thanks!

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

2 participants