diff --git a/.changeset/upset-hotels-mix.md b/.changeset/upset-hotels-mix.md new file mode 100644 index 000000000000..45b003eadee2 --- /dev/null +++ b/.changeset/upset-hotels-mix.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +fix: `RecursiveFormFields` type for recursive or unknown schemas diff --git a/packages/kit/src/exports/public.d.ts b/packages/kit/src/exports/public.d.ts index 84fd0bb3067e..cb42dc6cc1c0 100644 --- a/packages/kit/src/exports/public.d.ts +++ b/packages/kit/src/exports/public.d.ts @@ -1914,10 +1914,28 @@ type RemoteFormFieldContainer = RemoteFormFieldMethods & { allIssues(): RemoteFormIssue[] | undefined; }; +type UnknownField = RemoteFormFieldMethods & { + /** Validation issues belonging to this or any of the fields that belong to it, if any */ + allIssues(): RemoteFormIssue[] | undefined; + /** + * Returns an object that can be spread onto an input element with the correct type attribute, + * aria-invalid attribute if the field is invalid, and appropriate value/checked property getters/setters. + * @example + * ```svelte + * + * + * + * ``` + */ + as>(...args: AsArgs): InputElementProps; +} & { + [key: string | number]: UnknownField; +}; + /** * Recursive type to build form fields structure with proxy access */ -type RemoteFormFields = +export type RemoteFormFields = WillRecurseIndefinitely extends true ? RecursiveFormFields : NonNullable extends string | number | boolean | File @@ -1925,11 +1943,17 @@ type RemoteFormFields = : T extends string[] | File[] ? RemoteFormField & { [K in number]: RemoteFormField } : T extends Array - ? RemoteFormFieldContainer & { [K in number]: RemoteFormFields } - : RemoteFormFieldContainer & { [K in keyof T]-?: RemoteFormFields }; + ? RemoteFormFieldContainer & { + [K in number]: RemoteFormFields; + } + : RemoteFormFieldContainer & { + [K in keyof T]-?: RemoteFormFields; + }; // By breaking this out into its own type, we avoid the TS recursion depth limit -type RecursiveFormFields = RemoteFormField & { [key: string | number]: RecursiveFormFields }; +type RecursiveFormFields = RemoteFormFieldContainer & { + [key: string | number]: UnknownField; +}; type MaybeArray = T | T[]; diff --git a/packages/kit/types/index.d.ts b/packages/kit/types/index.d.ts index cc02ddb3e4c1..52fcb547490d 100644 --- a/packages/kit/types/index.d.ts +++ b/packages/kit/types/index.d.ts @@ -1890,10 +1890,28 @@ declare module '@sveltejs/kit' { allIssues(): RemoteFormIssue[] | undefined; }; + type UnknownField = RemoteFormFieldMethods & { + /** Validation issues belonging to this or any of the fields that belong to it, if any */ + allIssues(): RemoteFormIssue[] | undefined; + /** + * Returns an object that can be spread onto an input element with the correct type attribute, + * aria-invalid attribute if the field is invalid, and appropriate value/checked property getters/setters. + * @example + * ```svelte + * + * + * + * ``` + */ + as>(...args: AsArgs): InputElementProps; + } & { + [key: string | number]: UnknownField; + }; + /** * Recursive type to build form fields structure with proxy access */ - type RemoteFormFields = + export type RemoteFormFields = WillRecurseIndefinitely extends true ? RecursiveFormFields : NonNullable extends string | number | boolean | File @@ -1901,11 +1919,17 @@ declare module '@sveltejs/kit' { : T extends string[] | File[] ? RemoteFormField & { [K in number]: RemoteFormField } : T extends Array - ? RemoteFormFieldContainer & { [K in number]: RemoteFormFields } - : RemoteFormFieldContainer & { [K in keyof T]-?: RemoteFormFields }; + ? RemoteFormFieldContainer & { + [K in number]: RemoteFormFields; + } + : RemoteFormFieldContainer & { + [K in keyof T]-?: RemoteFormFields; + }; // By breaking this out into its own type, we avoid the TS recursion depth limit - type RecursiveFormFields = RemoteFormField & { [key: string | number]: RecursiveFormFields }; + type RecursiveFormFields = RemoteFormFieldContainer & { + [key: string | number]: UnknownField; + }; type MaybeArray = T | T[];