Skip to content
Merged
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/breezy-pots-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix to ActionData type generation
17 changes: 14 additions & 3 deletions packages/kit/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,20 @@ export type AwaitedProperties<input extends Record<string, any> | void> = input
? input
: unknown;

export type AwaitedActions<T extends Record<string, (...args: any) => any>> = {
[Key in keyof T]: UnpackValidationError<Awaited<ReturnType<T[Key]>>>;
}[keyof T];
export type AwaitedActions<T extends Record<string, (...args: any) => any>> = Expand<
{
[Key in keyof T]: OptionalUnion<UnpackValidationError<Awaited<ReturnType<T[Key]>>>>;
}[keyof T]
>;

// Makes sure a type is "repackaged" and therefore more readable
type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;
// 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
type OptionalUnion<
U extends Record<string, any>, // not unknown, else interfaces don't satisfy this constraint
A extends keyof U = U extends U ? keyof U : never
> = U extends unknown ? { [P in Exclude<A, keyof U>]?: never } & U : never;

// Needs to be here, else ActionData will be resolved to unknown - probably because of "d.ts file imports .js file" in combination with allowJs
interface ValidationError<T extends Record<string, unknown> | undefined = undefined> {
Expand Down