Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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/every-bears-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: allow access to root-level issues in schema-less forms
12 changes: 11 additions & 1 deletion packages/kit/src/exports/public.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
AdapterEntry,
CspDirectives,
HttpMethod,
IsAny,
Logger,
MaybePromise,
Prerendered,
Expand Down Expand Up @@ -2058,7 +2059,16 @@ export type RemoteForm<Input extends RemoteFormInput | void, Output> = {
/** The number of pending submissions */
get pending(): number;
/** Access form fields using object notation */
fields: Input extends void ? never : RemoteFormFields<Input>;
fields: IsAny<Input> extends true
? RecursiveFormFields
: Input extends void
? {
/** Validation issues, if any */
issues(): RemoteFormIssue[] | undefined;
/** Validation issues belonging to this or any of the fields that belong to it, if any */
allIssues(): RemoteFormIssue[] | undefined;
}
: RemoteFormFields<Input>;
/** Spread this onto a `<button>` or `<input type="submit">` */
buttonProps: {
type: 'submit';
Expand Down
2 changes: 2 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,5 @@ export interface RouteSegment {
}

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

export type IsAny<T> = 0 extends 1 & T ? true : false;
2 changes: 2 additions & 0 deletions packages/kit/test/types/remote.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ function form_tests() {
invalid.x('bar')
);
});
f8.fields.issues();
f8.fields.allIssues();
// @ts-expect-error
f8.fields.x;
// @ts-expect-error
Expand Down
13 changes: 12 additions & 1 deletion packages/kit/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2034,7 +2034,16 @@ declare module '@sveltejs/kit' {
/** The number of pending submissions */
get pending(): number;
/** Access form fields using object notation */
fields: Input extends void ? never : RemoteFormFields<Input>;
fields: IsAny<Input> extends true
? RecursiveFormFields
: Input extends void
? {
/** Validation issues, if any */
issues(): RemoteFormIssue[] | undefined;
/** Validation issues belonging to this or any of the fields that belong to it, if any */
allIssues(): RemoteFormIssue[] | undefined;
}
: RemoteFormFields<Input>;
/** Spread this onto a `<button>` or `<input type="submit">` */
buttonProps: {
type: 'submit';
Expand Down Expand Up @@ -2376,6 +2385,8 @@ declare module '@sveltejs/kit' {
}

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

type IsAny<T> = 0 extends 1 & T ? true : false;
interface Asset {
file: string;
size: number;
Expand Down
Loading