diff --git a/.changeset/breezy-cycles-thank.md b/.changeset/breezy-cycles-thank.md new file mode 100644 index 000000000000..23d8356a9bae --- /dev/null +++ b/.changeset/breezy-cycles-thank.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +fix: ensure types of all form actions are accessible even if differing diff --git a/packages/kit/test/types/actions.test.ts b/packages/kit/test/types/actions.test.ts index 35a32f2011da..8ca089d18c28 100644 --- a/packages/kit/test/types/actions.test.ts +++ b/packages/kit/test/types/actions.test.ts @@ -11,3 +11,15 @@ form.message = ''; form.success = true; // @ts-expect-error - cannot both be present at the same time form = { message: '', success: true }; + +// Test: Actions with different return types are transformed into a union that has all types accessible +type Actions2 = { + foo: () => Promise<{ message: string }>; + bar: () => Promise<{ success: boolean }>; +}; + +let form2: Kit.AwaitedActions = null as any; +form2.message = ''; +form2.success = true; +// @ts-expect-error - cannot both be present at the same time +form2 = { message: '', success: true }; diff --git a/packages/kit/types/index.d.ts b/packages/kit/types/index.d.ts index e7440202a024..ccc9a9d5e329 100644 --- a/packages/kit/types/index.d.ts +++ b/packages/kit/types/index.d.ts @@ -50,9 +50,11 @@ export type AwaitedProperties | void> = ? OptionalUnion> : AwaitedPropertiesUnion; -export type AwaitedActions any>> = { - [Key in keyof T]: OptionalUnion>>>; -}[keyof T]; +export type AwaitedActions any>> = OptionalUnion< + { + [Key in keyof T]: UnpackValidationError>>; + }[keyof T] +>; // Takes a union type and returns a union type where each type also has all properties // of all possible types (typed as undefined), making accessing them more ergonomic