[TypeScript] Can't use <Link /> with Gatsby <Link />
See original GitHub issueI want to use the Gatsby
Link component together with Chakras Link component. Unfortunately it seems not to work as expected because I’m getting compile errors:
import React from 'react';
import { Link as GatsbyLink } from 'gatsby';
import { Link } from '@chakra-ui/core';
export function Test() {
return (
<Link as={GatsbyLink} to="/me/">
Me
</Link>
);
}
produces a
Type 'typeof GatsbyLink' is not assignable to type '"symbol" | "object" | "a" | "abbr" | "address" | "area" | "article" | "aside" | "audio" | "b" | "base" | "bdi" | "bdo" | "big" | "blockquote" | "body" | "br" | "button" | "canvas" | ... 157 more ... | undefined'.
Type 'typeof GatsbyLink' is not assignable to type 'ComponentClass<any, any> & string'.
Type 'typeof GatsbyLink' is not assignable to type 'string'.ts(2322)
index.d.ts(154, 3): The expected type comes from property 'as' which is declared here on type 'IntrinsicAttributes & ILink & IPseudoBoxProps & RefAttributes<HTMLElement> & HTMLAttributes<HTMLElement> & LayoutProps & ColorProps & SpaceProps<ReactText> & ... 16 more ... & { ...; }'
Issue Analytics
- State:
- Created 4 years ago
- Comments:16 (9 by maintainers)
Top Results From Across the Web
Extending Gatsby Link in Typescript - Polynique
The Gatsby Link Typescript problem This means that Link is exported with the forwardRef property which gives access to the ref property, which ......
Read more >Wrapping Gatsby's <Link> with TypeScript - Nicolas Charpentier
This component is a wrapper around @reach/router's Link component that adds useful enhancements specific to Gatsby. All props are passed through ...
Read more >Using Gatsby Link with TypeScript - Stack Overflow
Show activity on this post. I'm using Gatsby Link with TypeScript and I want to pass parameters to linked component from source component....
Read more >Linking Between Pages | Gatsby
This guide covers how to link between pages in a Gatsby site. The Gatsby link component. The Gatsby <Link /> component is for...
Read more >gatsby-link - npm
Start using gatsby-link in your project by running `npm i gatsby-link`. ... TypeScript icon, indicating that this package has built-in type ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@alexluong You may opt out of type checking for an entire file with // @ts-ignore, but I wouldn’t recommend that.
An other choice is to create an alias for Link like below:
Personally, I’m using Chakra with the router of Gatsby and it made sense to create a custom
Link
component, using the first approach:Thank you @kripod !
As of typescript-eslint 3.0.0, I believe the command will now be
ban-ts-comment
instead ofban-ts-ignore