diff --git a/.changeset/nice-chairs-switch.md b/.changeset/nice-chairs-switch.md new file mode 100644 index 000000000000..21bf8304d17c --- /dev/null +++ b/.changeset/nice-chairs-switch.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +fix: deep partial `.value()` and `.set(...)` types for forms diff --git a/packages/kit/src/exports/public.d.ts b/packages/kit/src/exports/public.d.ts index cb42dc6cc1c0..5f46b4e640f8 100644 --- a/packages/kit/src/exports/public.d.ts +++ b/packages/kit/src/exports/public.d.ts @@ -15,7 +15,8 @@ import { PrerenderUnseenRoutesHandlerValue, PrerenderOption, RequestOptions, - RouteSegment + RouteSegment, + DeepPartial } from '../types/private.js'; import { BuildData, SSRNodeLoader, SSRRoute, ValidatedConfig } from 'types'; import { SvelteConfig } from '@sveltejs/vite-plugin-svelte'; @@ -1875,9 +1876,9 @@ type InputElementProps = T extends 'checkbox' | 'r type RemoteFormFieldMethods = { /** The values that will be submitted */ - value(): T; + value(): DeepPartial; /** Set the values that will be submitted */ - set(input: T): T; + set(input: DeepPartial): DeepPartial; /** Validation issues, if any */ issues(): RemoteFormIssue[] | undefined; }; diff --git a/packages/kit/src/types/private.d.ts b/packages/kit/src/types/private.d.ts index da512ed777c5..9345bdc0e522 100644 --- a/packages/kit/src/types/private.d.ts +++ b/packages/kit/src/types/private.d.ts @@ -241,3 +241,11 @@ export interface RouteSegment { } export type TrailingSlash = 'never' | 'always' | 'ignore'; + +export type DeepPartial = T extends Record | unknown[] + ? { + [K in keyof T]?: T[K] extends Record | unknown[] + ? DeepPartial + : T[K]; + } + : T | undefined; diff --git a/packages/kit/types/index.d.ts b/packages/kit/types/index.d.ts index 9fde95c8dd4c..1d808f7ac6ee 100644 --- a/packages/kit/types/index.d.ts +++ b/packages/kit/types/index.d.ts @@ -1851,9 +1851,9 @@ declare module '@sveltejs/kit' { type RemoteFormFieldMethods = { /** The values that will be submitted */ - value(): T; + value(): DeepPartial; /** Set the values that will be submitted */ - set(input: T): T; + set(input: DeepPartial): DeepPartial; /** Validation issues, if any */ issues(): RemoteFormIssue[] | undefined; }; @@ -2375,6 +2375,14 @@ declare module '@sveltejs/kit' { } type TrailingSlash = 'never' | 'always' | 'ignore'; + + type DeepPartial = T extends Record | unknown[] + ? { + [K in keyof T]?: T[K] extends Record | unknown[] + ? DeepPartial + : T[K]; + } + : T | undefined; interface Asset { file: string; size: number;