Skip to content

Commit a240240

Browse files
committed
Fixed type for form store, adding tainted option.
1 parent 27cfd7a commit a240240

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/lib/client/index.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import {
1414
get,
1515
writable,
1616
type Readable,
17-
type Writable
17+
type Writable,
18+
type Updater
1819
} from 'svelte/store';
1920
import { onDestroy, tick } from 'svelte';
2021
import { browser } from '$app/environment';
@@ -203,7 +204,15 @@ type SuperFormEventList<T extends AnyZodObject, M> = {
203204

204205
// eslint-disable-next-line @typescript-eslint/no-explicit-any
205206
export type SuperForm<T extends ZodValidation<AnyZodObject>, M = any> = {
206-
form: Writable<Validation<T, M>['data']>;
207+
form: {
208+
subscribe: Readable<z.infer<T>>['subscribe'];
209+
set(this: void, value: z.infer<T>, options: { taint?: boolean }): void;
210+
update(
211+
this: void,
212+
updater: Updater<z.infer<T>>,
213+
options: { taint?: boolean }
214+
): void;
215+
};
207216
formId: Writable<string | undefined>;
208217
errors: Writable<Validation<T, M>['errors']>;
209218
constraints: Writable<Validation<T, M>['constraints']>;

src/routes/tainted/+page.svelte

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@
6464
</div>
6565
{/each}
6666
<button>Submit</button>
67+
<button
68+
type="button"
69+
on:click={() => {
70+
form.update(
71+
($form) => {
72+
$form.tags[3].id = 7;
73+
return $form;
74+
},
75+
{ taint: false }
76+
);
77+
}}>Change without taint</button
78+
>
6779
</form>
6880

6981
<style lang="scss">

0 commit comments

Comments
 (0)