Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/blue-bears-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sveltejs/kit": patch
---

fix: add `null` to `RemoteFormInput` type to allow nullable schema validators
2 changes: 1 addition & 1 deletion packages/kit/src/exports/public.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2090,7 +2090,7 @@ type RecursiveFormFields = RemoteFormFieldContainer<any> & {
type MaybeArray<T> = T | T[];

export interface RemoteFormInput {
[key: string]: MaybeArray<string | number | boolean | File | RemoteFormInput>;
[key: string]: MaybeArray<string | number | boolean | File | null | undefined | RemoteFormInput>;
}

export interface RemoteFormIssue {
Expand Down
21 changes: 21 additions & 0 deletions packages/kit/test/types/remote.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,27 @@ function form_tests() {
f11_field2.propA;
// @ts-expect-error
f11_field2.propB;

// schema with nullable values (e.g. Zod nullable())
const f12 = form(
null as any as StandardSchemaV1<{
nullable_string: string | null;
nested: { nullable_value: number | null };
}>,
(data) => {
data.nullable_string === '' || data.nullable_string === null;
data.nested.nullable_value === 0 || data.nested.nullable_value === null;
// @ts-expect-error
data.nonexistent;
return { success: true };
}
);
// @ts-expect-error
f12.fields.as('text');
f12.fields.nullable_string.issues();
f12.fields.nullable_string.value();
f12.fields.nested.nullable_value.issues();
f12.fields.nested.nullable_value.value();
}
form_tests();

Expand Down
2 changes: 1 addition & 1 deletion packages/kit/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2064,7 +2064,7 @@ declare module '@sveltejs/kit' {
type MaybeArray<T> = T | T[];

export interface RemoteFormInput {
[key: string]: MaybeArray<string | number | boolean | File | RemoteFormInput>;
[key: string]: MaybeArray<string | number | boolean | File | null | undefined | RemoteFormInput>;
}

export interface RemoteFormIssue {
Expand Down
Loading