diff --git a/types/react-router-dom/index.d.ts b/types/react-router-dom/index.d.ts index 6cb00d15eb..c6025b5113 100644 --- a/types/react-router-dom/index.d.ts +++ b/types/react-router-dom/index.d.ts @@ -9,7 +9,7 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 -import { match } from "react-router"; +import { match } from 'react-router'; import * as React from 'react'; import * as H from 'history'; @@ -39,7 +39,7 @@ export { export interface BrowserRouterProps { basename?: string; - getUserConfirmation?: ((message: string, callback: (ok: boolean) => void) => void); + getUserConfirmation?: (message: string, callback: (ok: boolean) => void) => void; forceRefresh?: boolean; keyLength?: number; } @@ -47,7 +47,7 @@ export class BrowserRouter extends React.Component {} export interface HashRouterProps { basename?: string; - getUserConfirmation?: ((message: string, callback: (ok: boolean) => void) => void); + getUserConfirmation?: (message: string, callback: (ok: boolean) => void) => void; hashType?: 'slash' | 'noslash' | 'hashbang'; } export class HashRouter extends React.Component {} @@ -58,23 +58,28 @@ export interface LinkProps extends React.AnchorHTMLAttribut replace?: boolean; innerRef?: React.Ref; } -export class Link extends React.Component< - LinkProps, - any -> {} +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 NavLinkProps extends LinkProps { - activeClassName?: string; - activeStyle?: React.CSSProperties; - exact?: boolean; - strict?: boolean; - isActive?( - match: match, - location: H.Location, - ): boolean; - location?: H.Location; + activeClassName?: string; + activeStyle?: React.CSSProperties; + exact?: boolean; + strict?: boolean; + isActive?(match: match, location: H.Location): boolean; + location?: H.Location; } -export class NavLink extends React.Component< - NavLinkProps, - any -> {} +export function NavLink( + // TODO: Define this as ...params: Parameters> when only TypeScript >= 3.1 support is needed. + props: React.PropsWithoutRef> & React.RefAttributes, +): ReturnType>; +export interface NavLink + extends React.ForwardRefExoticComponent< + React.PropsWithoutRef> & React.RefAttributes + > {} diff --git a/types/react-router-dom/react-router-dom-tests.tsx b/types/react-router-dom/react-router-dom-tests.tsx index 0fefcbb195..e55739292e 100644 --- a/types/react-router-dom/react-router-dom-tests.tsx +++ b/types/react-router-dom/react-router-dom-tests.tsx @@ -5,19 +5,17 @@ import * as H from 'history'; const getIsActive = (extraProp: string) => (match: match, location: H.Location) => !!extraProp; interface Props extends NavLinkProps { - extraProp: string; + extraProp: string; } export default function(props: Props) { - const {extraProp, ...rest} = props; - const isActive = getIsActive(extraProp); - return ( - - ); + const { extraProp, ...rest } = props; + const isActive = getIsActive(extraProp); + return ; } type OtherProps = RouteComponentProps<{ - id: string; + id: string; }>; const Component: React.FC = props => { @@ -39,7 +37,20 @@ const MyLink: React.FC = props => = node => {}; ; +; +; +; const ref = React.createRef(); ; +; +; +; ; + +React.createElement & React.RefAttributes>(Link, { + to: { pathname: 'abc', state: { foo: 5 } }, +}); +React.createElement & React.RefAttributes>(NavLink, { + to: { pathname: 'abc', state: { foo: 5 } }, +});