Skip to content

Commit 35b9555

Browse files
authored
🤖 Merge PR DefinitelyTyped#71245 [@types/hotwired__turbo] Add missing fields to TurboSubmitEndEvent by @nanaya
1 parent 5213a3b commit 35b9555

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

‎types/hotwired__turbo/hotwired__turbo-tests.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,15 @@ document.addEventListener("turbo:frame-missing", function(event) {
9595
document.addEventListener("turbo:submit-start", function(event) {
9696
event.detail.formSubmission.stop();
9797
});
98+
99+
document.addEventListener("turbo:submit-end", function(event) {
100+
if (event.detail.success) {
101+
// $ExpectType FetchResponse
102+
event.detail.fetchResponse;
103+
} else {
104+
// $ExpectType Error|undefined
105+
event.detail.error;
106+
// $ExpectType FetchResponse|undefined
107+
event.detail.fetchResponse;
108+
}
109+
});

‎types/hotwired__turbo/index.d.ts‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,18 +187,16 @@ export interface FormSubmission {
187187
submitter?: HTMLButtonElement | HTMLInputElement;
188188
}
189189
export type FormSubmissionResult =
190-
| { success: boolean; fetchResponse: FetchResponse }
191-
| { success: false; error: Error };
190+
& { formSubmission: FormSubmission }
191+
& (
192+
| { success: true; error: undefined; fetchResponse: FetchResponse }
193+
| { success: false; error?: Error; fetchResponse?: FetchResponse }
194+
);
192195

193196
export type TurboSubmitStartEvent = CustomEvent<{
194197
formSubmission: FormSubmission;
195198
}>;
196-
export type TurboSubmitEndEvent = CustomEvent<
197-
& { formSubmission: FormSubmission }
198-
& {
199-
[K in keyof FormSubmissionResult]?: FormSubmissionResult[K];
200-
}
201-
>;
199+
export type TurboSubmitEndEvent = CustomEvent<FormSubmissionResult>;
202200

203201
export type TurboFrameMissingEvent = CustomEvent<{
204202
response: Response;

0 commit comments

Comments
 (0)