diff --git a/.changeset/breezy-pots-wave.md b/.changeset/breezy-pots-wave.md new file mode 100644 index 000000000000..483da04ce080 --- /dev/null +++ b/.changeset/breezy-pots-wave.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +fix to ActionData type generation diff --git a/packages/kit/types/index.d.ts b/packages/kit/types/index.d.ts index 0c9d7e8285cb..f969803c55a1 100644 --- a/packages/kit/types/index.d.ts +++ b/packages/kit/types/index.d.ts @@ -35,9 +35,20 @@ export type AwaitedProperties | void> = input ? input : unknown; -export type AwaitedActions any>> = { - [Key in keyof T]: UnpackValidationError>>; -}[keyof T]; +export type AwaitedActions any>> = Expand< + { + [Key in keyof T]: OptionalUnion>>>; + }[keyof T] +>; + +// Makes sure a type is "repackaged" and therefore more readable +type Expand = 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, // 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]?: 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 | undefined = undefined> {