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/nice-chairs-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: deep partial `.value()` and `.set(...)` types for forms
7 changes: 4 additions & 3 deletions packages/kit/src/exports/public.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -1875,9 +1876,9 @@ type InputElementProps<T extends keyof InputTypeMap> = T extends 'checkbox' | 'r

type RemoteFormFieldMethods<T> = {
/** The values that will be submitted */
value(): T;
value(): DeepPartial<T>;
/** Set the values that will be submitted */
set(input: T): T;
set(input: DeepPartial<T>): DeepPartial<T>;
/** Validation issues, if any */
issues(): RemoteFormIssue[] | undefined;
};
Expand Down
8 changes: 8 additions & 0 deletions packages/kit/src/types/private.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,11 @@ export interface RouteSegment {
}

export type TrailingSlash = 'never' | 'always' | 'ignore';

export type DeepPartial<T> = T extends Record<PropertyKey, unknown> | unknown[]
? {
[K in keyof T]?: T[K] extends Record<PropertyKey, unknown> | unknown[]
? DeepPartial<T[K]>
: T[K];
}
: T | undefined;
12 changes: 10 additions & 2 deletions packages/kit/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1851,9 +1851,9 @@ declare module '@sveltejs/kit' {

type RemoteFormFieldMethods<T> = {
/** The values that will be submitted */
value(): T;
value(): DeepPartial<T>;
/** Set the values that will be submitted */
set(input: T): T;
set(input: DeepPartial<T>): DeepPartial<T>;
/** Validation issues, if any */
issues(): RemoteFormIssue[] | undefined;
};
Expand Down Expand Up @@ -2375,6 +2375,14 @@ declare module '@sveltejs/kit' {
}

type TrailingSlash = 'never' | 'always' | 'ignore';

type DeepPartial<T> = T extends Record<PropertyKey, unknown> | unknown[]
? {
[K in keyof T]?: T[K] extends Record<PropertyKey, unknown> | unknown[]
? DeepPartial<T[K]>
: T[K];
}
: T | undefined;
interface Asset {
file: string;
size: number;
Expand Down
Loading