From 6e4ad80b709edfb613639545c3a9f2f27fc8d813 Mon Sep 17 00:00:00 2001 From: Pasi Eronen Date: Tue, 21 Nov 2017 12:37:19 +0200 Subject: [PATCH] react-router/react-router-dom: fix typing for getUserConfirmation and Prompt props --- types/react-router-dom/index.d.ts | 4 ++-- types/react-router/index.d.ts | 4 ++-- types/react-router/test/MemoryRouter.tsx | 7 ++++++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/types/react-router-dom/index.d.ts b/types/react-router-dom/index.d.ts index f19bfdee9a..47964f196f 100644 --- a/types/react-router-dom/index.d.ts +++ b/types/react-router-dom/index.d.ts @@ -27,7 +27,7 @@ export { export interface BrowserRouterProps { basename?: string; - getUserConfirmation?(): void; + getUserConfirmation?: ((message: string, callback: (ok: boolean) => void) => void); forceRefresh?: boolean; keyLength?: number; } @@ -35,7 +35,7 @@ export class BrowserRouter extends React.Component {} export interface HashRouterProps { basename?: string; - getUserConfirmation?(): void; + getUserConfirmation?: ((message: string, callback: (ok: boolean) => void) => void); hashType?: 'slash' | 'noslash' | 'hashbang'; } export class HashRouter extends React.Component {} diff --git a/types/react-router/index.d.ts b/types/react-router/index.d.ts index 548e7ef4a1..9675badbf7 100644 --- a/types/react-router/index.d.ts +++ b/types/react-router/index.d.ts @@ -34,14 +34,14 @@ export interface RouterChildContext

{ export interface MemoryRouterProps { initialEntries?: H.LocationDescriptor[]; initialIndex?: number; - getUserConfirmation?: (() => void); + getUserConfirmation?: ((message: string, callback: (ok: boolean) => void) => void); keyLength?: number; } export class MemoryRouter extends React.Component { } export interface PromptProps { - message: string | ((location: H.Location) => void); + message: string | ((location: H.Location) => string | boolean); when?: boolean; } export class Prompt extends React.Component { } diff --git a/types/react-router/test/MemoryRouter.tsx b/types/react-router/test/MemoryRouter.tsx index 99aa385bd5..bd42d69407 100644 --- a/types/react-router/test/MemoryRouter.tsx +++ b/types/react-router/test/MemoryRouter.tsx @@ -12,8 +12,13 @@ const initialRouterEntries = [ } ]; +const getConfirmation = (message: string, callback: (ok: boolean) => void): void => { + const allowTransition = window.confirm(message); + callback(allowTransition); +}; + const MemoryRouterExample = () => ( - +

  • Home