Skip to content

Commit 1be3f0b

Browse files
committed
fix types so that TS knows the response has already been awaited
1 parent d34938d commit 1be3f0b

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

src/lib/command-form/command-form.svelte.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class CommandForm<Schema extends StandardSchemaV1, TOut> {
1717
errors = $state<CommandFormErrors<SchemaData<Schema>>>({});
1818
issues = $state<SchemaIssues | null>(null);
1919
private _submitting = $state(false);
20-
private _result = $state<TOut | null>(null);
20+
private _result = $state<Awaited<TOut> | null>(null);
2121

2222
constructor(schema: Schema, options: CommandFormOptions<SchemaData<Schema>, TOut>) {
2323
this.schema = schema;
@@ -91,7 +91,7 @@ export class CommandForm<Schema extends StandardSchemaV1, TOut> {
9191
}
9292
};
9393

94-
submit = async (): Promise<TOut | null> => {
94+
submit = async (): Promise<Awaited<TOut> | null> => {
9595
this._submitting = true;
9696
this.clearErrors();
9797
this._result = null;

src/lib/types/command-form.types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type CommandFormOptions<TIn, TOut> = {
1212
command: RemoteCommand<TIn, TOut>;
1313
reset?: 'onSuccess' | 'always' | 'onError';
1414
onSubmit?: (data: TIn) => Promise<void> | void;
15-
onSuccess?: (result: TOut) => Promise<void> | void;
15+
onSuccess?: (result: Awaited<TOut>) => Promise<void> | void;
1616
onError?: (err: unknown) => Promise<void> | void;
1717
};
1818

src/routes/+page.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
},
1414
onSuccess: async (res) => {
1515
console.log('success');
16+
console.log(res.success);
1617
},
1718
onError: async (err) => {
1819
console.log('error', err);

0 commit comments

Comments
 (0)