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

Wrong declaration of GatsbyLink with typescript 2.4.2 #1627

Closed
DominikGuzei opened this issue Jul 26, 2017 · 5 comments
Closed

Wrong declaration of GatsbyLink with typescript 2.4.2 #1627

DominikGuzei opened this issue Jul 26, 2017 · 5 comments

Comments

@DominikGuzei
Copy link
Contributor

DominikGuzei commented Jul 26, 2017

Hey there, im trying to use Gatsby with typescript 2.4.2 but it throws an error telling me that the signature of the GatsbyLink export is wrong:

export default class GatsbyLink extends React.Component<GatsbyLinkProps, void> { }

I could fix it by changing it to

export default class GatsbyLink extends React.Component<GatsbyLinkProps> { }

Im just running the starter code for index.tsx:

import * as React from 'react';
import Link from 'gatsby-link';

const IndexPage = () => (
  <div>
    <h1>Hi people</h1>
    <p>Welcome to your new Gatsby site.</p>
    <p>Now go build something great.</p>
    <Link to="/page-2/">Go to page 2</Link>
  </div>
);

export default IndexPage;

The error message:

Error:(9, 5) TS2605:JSX element type 'GatsbyLink' is not a constructor function for JSX elements.
  Types of property 'setState' are incompatible.
    Type '{ <K extends never>(f: (prevState: void, props: GatsbyLinkProps) => Pick<void, K>, callback?: (()...' is not assignable to type '{ <K extends never>(f: (prevState: {}, props: any) => Pick<{}, K>, callback?: (() => any) | undef...'.
      Types of parameters 'f' and 'f' are incompatible.
        Types of parameters 'prevState' and 'prevState' are incompatible.
          Type 'void' is not assignable to type '{}'.

my tsconfig:

{
  "compilerOptions": {
    "outDir": "./dist/",
    "sourceMap": true,
    "noImplicitAny": true,
    "strict": true,
    "strictNullChecks": true,
    "module": "commonjs",
    "target": "esnext",
    "jsx": "react",
    "lib": ["dom", "es2015", "es2017"]
  },
  "include": [
    "./src/**/*"
  ]
}

See last comment on this issue to see how i found the fix.

@KyleAMathews
Copy link
Contributor

@timsuchanek and @fabien0102 comments?

@timsuchanek
Copy link
Contributor

I think the problem is that Typescript got stricter about the generics, in this case the void. With removing the void, it's then using the default {}. (https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react/index.d.ts#L238)
Do you want to create a PR for that @DominikGuzei ?

@DominikGuzei
Copy link
Contributor Author

@timsuchanek yeah sure, will set it up!

@DominikGuzei
Copy link
Contributor Author

@timsuchanek the fix is ready for review: #1628

@KyleAMathews
Copy link
Contributor

Fixed in #1628

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