diff --git a/types/hotwired__turbo/hotwired__turbo-tests.ts b/types/hotwired__turbo/hotwired__turbo-tests.ts index 4d6759313b4c53..4bc74319abaabc 100644 --- a/types/hotwired__turbo/hotwired__turbo-tests.ts +++ b/types/hotwired__turbo/hotwired__turbo-tests.ts @@ -15,6 +15,7 @@ import { StreamActions, StreamMessage, StreamSource, + TurboHistory, Visit, visit, VisitOptions, @@ -289,3 +290,29 @@ StreamMessage.contentType; // $ExpectType StreamMessage StreamMessage.wrap(""); + +// Test TurboHistory via session.history +// $ExpectType TurboHistory +session.history; +// $ExpectType TurboHistory +Turbo.session.history; + +session.history.push(new URL("https://example.com")); +session.history.push(new URL("https://example.com"), "abc-123"); +session.history.replace(new URL("https://example.com")); +session.history.replace(new URL("https://example.com"), "abc-123"); + +// $ExpectType URL +session.history.location; +// $ExpectType string +session.history.restorationIdentifier; + +// Test session getters +// $ExpectType URL +session.location; +// $ExpectType string +session.restorationIdentifier; +// $ExpectType boolean +session.started; +// $ExpectType boolean +session.enabled; diff --git a/types/hotwired__turbo/index.d.ts b/types/hotwired__turbo/index.d.ts index db2e65f42f58bd..bfd2d8a12449be 100644 --- a/types/hotwired__turbo/index.d.ts +++ b/types/hotwired__turbo/index.d.ts @@ -277,12 +277,26 @@ export function disconnectStreamSource(source: StreamSource): void; */ export function renderStreamMessage(message: StreamMessage | string): void; +export interface TurboHistory { + readonly location: URL; + readonly restorationIdentifier: string; + push(location: URL, restorationIdentifier?: string): void; + replace(location: URL, restorationIdentifier?: string): void; +} + export interface TurboSession { + readonly history: TurboHistory; + adapter: Adapter; + readonly enabled: boolean; + readonly started: boolean; + connectStreamSource(source: StreamSource): void; disconnectStreamSource(source: StreamSource): void; renderStreamMessage(message: StreamMessage | string): void; + drive: boolean; - adapter: Adapter; + readonly location: URL; + readonly restorationIdentifier: string; } export const StreamActions: {