Skip to content

Commit 56f679b

Browse files
authored
fix: correctly type form remote functions that do not accept data (#14573)
* fix * changeset * generate types * test
1 parent 275ab4d commit 56f679b

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

.changeset/lucky-humans-make.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
fix: correctly type the `result` of `form` remote functions that do not accept data

packages/kit/src/runtime/app/server/remote/form.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { convert_formdata, flatten_issues } from '../../../utils.js';
1313
*
1414
* @template Output
1515
* @overload
16-
* @param {() => Output} fn
16+
* @param {() => MaybePromise<Output>} fn
1717
* @returns {RemoteForm<void, Output>}
1818
* @since 2.27
1919
*/

packages/kit/test/types/remote.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,11 @@ function form_tests() {
301301
f6.input!['array[0].array[]'] = [''];
302302
// @ts-expect-error
303303
f6.input!['array[0].prop'] = 123;
304+
305+
// doesn't use data
306+
// eslint-disable-next-line @typescript-eslint/require-await --- we are testing that the async function does not cause `result` to be typed as a Promise
307+
const f7 = form(async () => ({ success: true }));
308+
f7.result?.success === true;
304309
}
305310
form_tests();
306311

packages/kit/types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3061,7 +3061,7 @@ declare module '$app/server' {
30613061
*
30623062
* @since 2.27
30633063
*/
3064-
export function form<Output>(fn: () => Output): RemoteForm<void, Output>;
3064+
export function form<Output>(fn: () => MaybePromise<Output>): RemoteForm<void, Output>;
30653065
/**
30663066
* Creates a form object that can be spread onto a `<form>` element.
30673067
*

0 commit comments

Comments
 (0)