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
15 changes: 15 additions & 0 deletions types/hotwired__turbo/hotwired__turbo-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ StreamActions.log = function() {
console.log(this.getAttribute("message"));
};

document.addEventListener("turbo:before-fetch-request", function(event) {
// $ExpectType FetchRequestHeaders
const headers = event.detail.fetchOptions.headers;
headers["Turbo-Referrer"] = window.location.href;
// $ExpectType string | undefined
headers.Accept;
});

document.addEventListener("turbo:before-fetch-response", function(e) {
let { fetchResponse } = e.detail;
fetchResponse.header("foo");
Expand All @@ -106,6 +114,13 @@ document.addEventListener("turbo:before-render", function(e) {
// $ExpectType HTMLBodyElement
newElement;
};
// $ExpectType (value?: unknown) => void
e.detail.resume;
});

document.addEventListener("turbo:before-frame-render", function(e) {
// $ExpectType (value?: unknown) => void
e.detail.resume;
});

document.addEventListener("turbo:frame-missing", function(event) {
Expand Down
14 changes: 9 additions & 5 deletions types/hotwired__turbo/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,15 @@ export class StreamMessage {
constructor(fragment: DocumentFragment);
}

export interface FetchRequestHeaders {
[header: string]: string | undefined;
}

export class FetchRequest {
body: FormData | URLSearchParams;
enctype: "application/x-www-form-urlencoded" | "multipart/form-data" | "text/plain";
fetchOptions: RequestInit;
headers: Headers | { [k: string]: any };
headers: FetchRequestHeaders;
method: "get" | "post" | "put" | "patch" | "delete";
params: URLSearchParams;
target: HTMLFormElement | HTMLAnchorElement | FrameElement | null;
Expand Down Expand Up @@ -407,7 +411,7 @@ export type TurboBeforeRenderEvent = CustomEvent<{
newBody: HTMLBodyElement;
renderMethod: "replace" | "morph";
isPreview: boolean;
resume: (value?: any) => void;
resume: (value?: unknown) => void;
render: (currentBody: HTMLBodyElement, newBody: HTMLBodyElement) => void;
}>;
export type TurboBeforeVisitEvent = CustomEvent<{ url: string }>;
Expand All @@ -418,7 +422,7 @@ export type TurboClickEvent = CustomEvent<{
export type TurboFrameLoadEvent = CustomEvent;
export type TurboBeforeFrameRenderEvent = CustomEvent<{
newFrame: FrameElement;
resume: (value?: any) => void;
resume: (value?: unknown) => void;
render: (currentFrame: FrameElement, newFrame: FrameElement) => void;
}>;
export type TurboFrameRenderEvent = CustomEvent<{
Expand Down Expand Up @@ -489,9 +493,9 @@ export type TurboFrameMissingEvent = CustomEvent<{
}>;

export type TurboBeforeFetchRequestEvent = CustomEvent<{
fetchOptions: RequestInit;
fetchOptions: Omit<RequestInit, "headers"> & { headers: FetchRequestHeaders };
url: URL;
resume: (value: any) => void;
resume: (value?: unknown) => void;
}>;

export type TurboBeforeFetchResponseEvent = CustomEvent<{
Expand Down