Skip to content

Commit e1673a6

Browse files
committed
newState signature must be partial to work with unions.
1 parent db7f68f commit e1673a6

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

src/lib/client/superForm.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ type SuperFormErrors<T extends Record<string, unknown>> = {
191191
type ResetOptions<T extends Record<string, unknown>> = {
192192
keepMessage?: boolean;
193193
data?: Partial<T>;
194-
newState?: T;
194+
newState?: Partial<T>;
195195
id?: string;
196196
};
197197

@@ -924,7 +924,7 @@ export function superForm<
924924
posted?: boolean;
925925
} = {}
926926
) {
927-
if (opts.newState) initialForm.data = opts.newState;
927+
if (opts.newState) initialForm.data = { ...initialForm.data, ...opts.newState };
928928

929929
const resetData = clone(initialForm);
930930
resetData.data = { ...resetData.data, ...opts.data };

src/routes/(v2)/v2/allow-files/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<form method="POST" enctype="multipart/form-data" use:enhance>
2323
<label>
2424
Upload file, max 10 Kb: <input
25-
on:input={(e) => ($form.avatar = e.currentTarget.files?.item(0) as File)}
25+
on:input={(e) => ($form.avatar = e.currentTarget.files?.item(0) ?? null)}
2626
accept="image/png, image/jpeg"
2727
name="avatar"
2828
type="file"

src/routes/(v2)/v2/allow-files/schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export const schema = z.object({
44
avatar: z
55
.instanceof(File, { message: 'Please upload a file.' })
66
.refine((f) => f.size < 10_000, 'Max 10Kb upload size.')
7+
.nullable()
78
});

0 commit comments

Comments
 (0)