From f02e24a952080098d4da9f2dacd465b022c82edd Mon Sep 17 00:00:00 2001 From: Paul Siegrist Date: Tue, 26 Nov 2024 16:54:45 +0100 Subject: [PATCH 1/2] 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. --- packages/gatsby-link/index.d.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/gatsby-link/index.d.ts b/packages/gatsby-link/index.d.ts index 69cebfaaa1826..0ca8553e8ac6b 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,11 @@ 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; +interface NavigateFn { + (to: string, options?: NavigateOptions<{}>): void + (to: number): void +} +export const navigate: NavigateFn /** * It is common to host sites in a sub-directory of a site. Gatsby lets you set the path prefix for your site. From bfb47bdeccebc56e01cdb0f345efef599ddd3f3d Mon Sep 17 00:00:00 2001 From: Paul Siegrist Date: Wed, 27 Nov 2024 11:35:31 +0100 Subject: [PATCH 2/2] Replace interface and define parameter overloading inline; --- packages/gatsby-link/index.d.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/gatsby-link/index.d.ts b/packages/gatsby-link/index.d.ts index 0ca8553e8ac6b..c8c2ec1328831 100644 --- a/packages/gatsby-link/index.d.ts +++ b/packages/gatsby-link/index.d.ts @@ -33,11 +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. */ -interface NavigateFn { +export const navigate: { (to: string, options?: NavigateOptions<{}>): void (to: number): void } -export const navigate: NavigateFn /** * It is common to host sites in a sub-directory of a site. Gatsby lets you set the path prefix for your site.