Skip to content

Commit

Permalink
fix(gatsby-link): fix navigate method type (#39188)
Browse files Browse the repository at this point in the history
* Fixes type of navigate method

The usage of the original navigation function type created problems when using spreaded parameters. Since the navigate implementation in gatsby does not have the same call signature as @reach/router anyways (the promise returned by @reach/router is ignored), it is easier to define our own interface than to overwrite the types from @reach/router.

* Replace interface and define parameter overloading inline;

---------

Co-authored-by: Philippe Serhal <[email protected]>
(cherry picked from commit cddc252)

Co-authored-by: pajosieg <[email protected]>
  • Loading branch information
gatsbybot and pajosieg authored Dec 20, 2024
1 parent 4de4fb8 commit 139aedd
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/gatsby-link/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from "react"
import { NavigateFn, LinkProps } from "@reach/router" // These come from `@types/reach__router`
import { NavigateOptions, LinkProps } from "@reach/router" // These come from `@types/reach__router`

// eslint-disable-next-line @typescript-eslint/naming-convention
export interface GatsbyLinkProps<TState> extends LinkProps<TState> {
Expand Down Expand Up @@ -33,7 +33,10 @@ export class Link<TState> extends React.Component<
* Sometimes you need to navigate to pages programmatically, such as during form submissions. In these
* cases, `Link` won’t work.
*/
export const navigate: (...args: Parameters<NavigateFn>) => void;
export const navigate: {
(to: string, options?: NavigateOptions<{}>): void
(to: number): void
}

/**
* It is common to host sites in a sub-directory of a site. Gatsby lets you set the path prefix for your site.
Expand Down

0 comments on commit 139aedd

Please sign in to comment.