Skip to content

Commit c097941

Browse files
BrianzchenBrian Chen
andauthored
[history] Fix partial error (#4563)
* break down into multiple versions * update shape to partial * fix tests --------- Co-authored-by: Brian Chen <[email protected]>
1 parent e194262 commit c097941

File tree

12 files changed

+1308
-1
lines changed

12 files changed

+1308
-1
lines changed
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
declare module 'history' {
2+
declare function Unblock(): void;
3+
4+
declare export type Action = 'PUSH' | 'REPLACE' | 'POP';
5+
6+
declare export type BrowserLocation = {
7+
pathname: string,
8+
search: string,
9+
hash: string,
10+
// Browser and Memory specific
11+
state: {...},
12+
key: string,
13+
...
14+
};
15+
16+
declare interface IBrowserHistory {
17+
length: number;
18+
location: BrowserLocation;
19+
action: Action;
20+
push(path: string, state?: {...}): void;
21+
push(location: Partial<BrowserLocation>): void;
22+
replace(path: string, state?: {...}): void;
23+
replace(location: Partial<BrowserLocation>): void;
24+
go(n: number): void;
25+
goBack(): void;
26+
goForward(): void;
27+
listen((location: BrowserLocation, action: Action) => void): void;
28+
block(message: string): typeof Unblock;
29+
block(
30+
(location: BrowserLocation, action: Action) => string
31+
): typeof Unblock;
32+
}
33+
34+
declare export type BrowserHistory = IBrowserHistory;
35+
36+
declare type BrowserHistoryOpts = {
37+
basename?: string,
38+
forceRefresh?: boolean,
39+
getUserConfirmation?: (
40+
message: string,
41+
callback: (willContinue: boolean) => void
42+
) => void,
43+
...
44+
};
45+
46+
declare function createBrowserHistory(
47+
opts?: BrowserHistoryOpts
48+
): BrowserHistory;
49+
50+
declare export type MemoryLocation = {
51+
pathname: string,
52+
search: string,
53+
hash: string,
54+
// Browser and Memory specific
55+
state: {...},
56+
key: string,
57+
...
58+
};
59+
60+
declare interface IMemoryHistory {
61+
length: number;
62+
location: MemoryLocation;
63+
action: Action;
64+
index: number;
65+
entries: Array<string>;
66+
push(path: string, state?: {...}): void;
67+
push(location: Partial<MemoryLocation>): void;
68+
replace(path: string, state?: {...}): void;
69+
replace(location: Partial<MemoryLocation>): void;
70+
go(n: number): void;
71+
goBack(): void;
72+
goForward(): void;
73+
// Memory only
74+
canGo(n: number): boolean;
75+
listen((location: MemoryLocation, action: Action) => void): void;
76+
block(message: string): typeof Unblock;
77+
block((location: MemoryLocation, action: Action) => string): typeof Unblock;
78+
}
79+
80+
declare export type MemoryHistory = IMemoryHistory;
81+
82+
declare type MemoryHistoryOpts = {
83+
initialEntries?: Array<string>,
84+
initialIndex?: number,
85+
keyLength?: number,
86+
getUserConfirmation?: (
87+
message: string,
88+
callback: (willContinue: boolean) => void
89+
) => void,
90+
...
91+
};
92+
93+
declare function createMemoryHistory(opts?: MemoryHistoryOpts): MemoryHistory;
94+
95+
declare export type HashLocation = {
96+
pathname: string,
97+
search: string,
98+
hash: string,
99+
...
100+
};
101+
102+
declare interface IHashHistory {
103+
length: number;
104+
location: HashLocation;
105+
action: Action;
106+
push(path: string, state?: {...}): void;
107+
push(location: Partial<HashLocation>): void;
108+
replace(path: string, state?: {...}): void;
109+
replace(location: Partial<HashLocation>): void;
110+
go(n: number): void;
111+
goBack(): void;
112+
goForward(): void;
113+
listen((location: HashLocation, action: Action) => void): void;
114+
block(message: string): typeof Unblock;
115+
block((location: HashLocation, action: Action) => string): typeof Unblock;
116+
push(path: string): void;
117+
}
118+
119+
declare export type HashHistory = IHashHistory;
120+
121+
declare type HashHistoryOpts = {
122+
basename?: string,
123+
hashType: 'slash' | 'noslash' | 'hashbang',
124+
getUserConfirmation?: (
125+
message: string,
126+
callback: (willContinue: boolean) => void
127+
) => void,
128+
...
129+
};
130+
131+
declare function createHashHistory(opts?: HashHistoryOpts): HashHistory;
132+
133+
declare function parsePath(path: string): BrowserLocation | MemoryLocation | HashLocation;
134+
135+
declare function createPath(
136+
path: BrowserLocation | MemoryLocation | HashLocation
137+
): string;
138+
}

0 commit comments

Comments
 (0)