From 52a012c3621b3a7cfa915b062ce6eba581b8ff3e Mon Sep 17 00:00:00 2001 From: zackzeno Date: Thu, 11 Oct 2018 14:55:48 -0400 Subject: [PATCH] [@types/history] History should be generic (#29024) * Make exec / createRow methods generic Saying they take/return Object is inaccurate, I wasn't sure if they should use object, any, or T extends object. I went with T extends object since it seems most correct. * Update tests * Update lint * Replace generic with object from "Common Mistakes" * Make History object generic * Make History object generic * Fix MemoryHistory definition, Fixed tested --- types/history/createMemoryHistory.d.ts | 6 +++--- types/history/history-tests.ts | 6 +++--- types/history/index.d.ts | 14 +++++++------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/types/history/createMemoryHistory.d.ts b/types/history/createMemoryHistory.d.ts index e1aca026e2..6142f4e3a4 100644 --- a/types/history/createMemoryHistory.d.ts +++ b/types/history/createMemoryHistory.d.ts @@ -1,4 +1,4 @@ -import { History, Location } from './index'; +import { History, Location, LocationState } from './index'; import { getConfirmation } from './DOMUtils'; export interface MemoryHistoryBuildOptions { @@ -8,9 +8,9 @@ export interface MemoryHistoryBuildOptions { keyLength?: number; } -export interface MemoryHistory extends History { +export interface MemoryHistory extends History { index: number; - entries: Location[]; + entries: Location[]; canGo(n: number): boolean; } diff --git a/types/history/history-tests.ts b/types/history/history-tests.ts index 0a63059b12..689035c9ed 100644 --- a/types/history/history-tests.ts +++ b/types/history/history-tests.ts @@ -1,4 +1,4 @@ -import { createBrowserHistory, createMemoryHistory, createHashHistory, createLocation, Location } from 'history'; +import { createBrowserHistory, createMemoryHistory, createHashHistory, createLocation, Location, History, MemoryHistory } from 'history'; import * as LocationUtils from 'history/LocationUtils'; import * as PathUtils from 'history/PathUtils'; import * as DOMUtils from 'history/DOMUtils'; @@ -7,7 +7,7 @@ import * as ExecutionEnvironment from 'history/ExecutionEnvironment'; let input = { value: "" }; { - let history = createBrowserHistory(); + let history: History<{some: 'state'}> = createBrowserHistory(); // Listen for changes to the current location. The // listener is called once immediately. @@ -43,7 +43,7 @@ let input = { value: "" }; } { - let history = createMemoryHistory(); + let history: MemoryHistory<{the: 'state'}> = createMemoryHistory(); // Pushing a path string. history.push('/the/path'); diff --git a/types/history/index.d.ts b/types/history/index.d.ts index 1c7b35b8f2..3fff510bd2 100644 --- a/types/history/index.d.ts +++ b/types/history/index.d.ts @@ -8,20 +8,20 @@ export as namespace History; export type Action = 'PUSH' | 'POP' | 'REPLACE'; export type UnregisterCallback = () => void; -export interface History { +export interface History { length: number; action: Action; - location: Location; - push(path: Path, state?: LocationState): void; - push(location: LocationDescriptorObject): void; - replace(path: Path, state?: LocationState): void; - replace(location: LocationDescriptorObject): void; + location: Location; + push(path: Path, state?: HistoryLocationState): void; + push(location: LocationDescriptorObject): void; + replace(path: Path, state?: HistoryLocationState): void; + replace(location: LocationDescriptorObject): void; go(n: number): void; goBack(): void; goForward(): void; block(prompt?: boolean | string | TransitionPromptHook): UnregisterCallback; listen(listener: LocationListener): UnregisterCallback; - createHref(location: LocationDescriptorObject): Href; + createHref(location: LocationDescriptorObject): Href; } export interface Location {