Skip to content

Commit ec1a16d

Browse files
authored
🤖 Merge PR DefinitelyTyped#75046 [hotwired__turbo] Add TurboHistory interface by @myabc
1 parent 794bc1f commit ec1a16d

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

types/hotwired__turbo/hotwired__turbo-tests.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
StreamActions,
1616
StreamMessage,
1717
StreamSource,
18+
TurboHistory,
1819
Visit,
1920
visit,
2021
VisitOptions,
@@ -289,3 +290,29 @@ StreamMessage.contentType;
289290

290291
// $ExpectType StreamMessage
291292
StreamMessage.wrap("<turbo-stream></turbo-stream>");
293+
294+
// Test TurboHistory via session.history
295+
// $ExpectType TurboHistory
296+
session.history;
297+
// $ExpectType TurboHistory
298+
Turbo.session.history;
299+
300+
session.history.push(new URL("https://example.com"));
301+
session.history.push(new URL("https://example.com"), "abc-123");
302+
session.history.replace(new URL("https://example.com"));
303+
session.history.replace(new URL("https://example.com"), "abc-123");
304+
305+
// $ExpectType URL
306+
session.history.location;
307+
// $ExpectType string
308+
session.history.restorationIdentifier;
309+
310+
// Test session getters
311+
// $ExpectType URL
312+
session.location;
313+
// $ExpectType string
314+
session.restorationIdentifier;
315+
// $ExpectType boolean
316+
session.started;
317+
// $ExpectType boolean
318+
session.enabled;

types/hotwired__turbo/index.d.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,26 @@ export function disconnectStreamSource(source: StreamSource): void;
277277
*/
278278
export function renderStreamMessage(message: StreamMessage | string): void;
279279

280+
export interface TurboHistory {
281+
readonly location: URL;
282+
readonly restorationIdentifier: string;
283+
push(location: URL, restorationIdentifier?: string): void;
284+
replace(location: URL, restorationIdentifier?: string): void;
285+
}
286+
280287
export interface TurboSession {
288+
readonly history: TurboHistory;
289+
adapter: Adapter;
290+
readonly enabled: boolean;
291+
readonly started: boolean;
292+
281293
connectStreamSource(source: StreamSource): void;
282294
disconnectStreamSource(source: StreamSource): void;
283295
renderStreamMessage(message: StreamMessage | string): void;
296+
284297
drive: boolean;
285-
adapter: Adapter;
298+
readonly location: URL;
299+
readonly restorationIdentifier: string;
286300
}
287301

288302
export const StreamActions: {

0 commit comments

Comments
 (0)