From 139aedd6c91d2ec655bfa4996beaaa39b8d84c65 Mon Sep 17 00:00:00 2001 From: GatsbyJS Bot Date: Fri, 20 Dec 2024 11:27:32 -0500 Subject: [PATCH] fix(gatsby-link): fix navigate method type (#39188) * 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 (cherry picked from commit cddc252bf4cac57486ed5f5b544d50e4a92ce769) Co-authored-by: pajosieg --- packages/gatsby-link/index.d.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/gatsby-link/index.d.ts b/packages/gatsby-link/index.d.ts index 69cebfaaa1826..c8c2ec1328831 100644 --- a/packages/gatsby-link/index.d.ts +++ b/packages/gatsby-link/index.d.ts @@ -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 extends LinkProps { @@ -33,7 +33,10 @@ export class Link 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) => 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.