diff --git a/types/reach__router/index.d.ts b/types/reach__router/index.d.ts index 00554e74f9..d48dc7cca2 100644 --- a/types/reach__router/index.d.ts +++ b/types/reach__router/index.d.ts @@ -69,7 +69,14 @@ export interface LinkGetProps { location: WindowLocation; } -export class Link extends React.Component> {} +export function Link( + // TODO: Define this as ...params: Parameters> when only TypeScript >= 3.1 support is needed. + props: React.PropsWithoutRef> & React.RefAttributes, +): ReturnType>; +export interface Link + extends React.ForwardRefExoticComponent< + React.PropsWithoutRef> & React.RefAttributes + > {} export interface RedirectProps { from?: string; diff --git a/types/reach__router/reach__router-tests.tsx b/types/reach__router/reach__router-tests.tsx index fe903f4f71..ab4a872a30 100644 --- a/types/reach__router/reach__router-tests.tsx +++ b/types/reach__router/reach__router-tests.tsx @@ -59,6 +59,17 @@ const handleRef = (el: HTMLAnchorElement) => { }; render(, document.getElementById('app-root')); +render(, document.getElementById('app-root')); const refObject: React.RefObject = { current: null }; render(, document.getElementById('app-root')); +render(, document.getElementById('app-root')); + +// Link can be used as a generic. +// TODO: When TS >= 3.1 is supported, use more modern syntax: +// state={5} to="./foo"> +React.createElement(Link as Link, { + state: 5 /* Cast is a test-only fix for TS 3.1. Remove when TS >= 3.2 is supported. */ as number | undefined, + to: './foo', + ref: refObject /* Cast is a test-only fix for TS 3.1. Remove when TS >= 3.2 is supported. */ as React.Ref | undefined +});