Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions types/hotwired__turbo/hotwired__turbo-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
StreamActions,
StreamMessage,
StreamSource,
TurboHistory,
Visit,
visit,
VisitOptions,
Expand Down Expand Up @@ -289,3 +290,29 @@ StreamMessage.contentType;

// $ExpectType StreamMessage
StreamMessage.wrap("<turbo-stream></turbo-stream>");

// 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;
16 changes: 15 additions & 1 deletion types/hotwired__turbo/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down