-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
Describe the bug
This is only an issue with the generated ActionData-type, not the hydration of the form-property.
When an action is calling fail() multiple places, with different shapes of data, it seems that the generated type will be narrowed down to the shape, that only shares the common properties of all the possible shapes.
This results to Property 'x' does not exist on type 'y'-errors, when trying to access those properties in the +page.svelte component
This seems like a bug. Though not of high severance, as it can be circumvented, by just adding the properties to data-objects where needed.
Related:
- ActionData generated type missing some properties in the template because of the way it does union #8865
- fix: ensure types of all form actions are accessible #8877
Reproduction
https://github.com/jeppech/incorrect-actiondata-multiple-fail-fn
- src/routes/+page.server.ts (named actions)
- src/routes/default/+page.server.ts (default action)
This is a plain create-svelte@latest-repo, that demonstrates how the generated ActionData-type is missing optional properties.
When the data-parameter of fail(), partially matches other shapes, in any other call to the fail-function, the generated type will be narrowed down to the "common" properties of all shapes.
Logs
No response
System Info
❯ pnpx envinfo --system --binaries --browsers --npmPackages "{svelte,@sveltejs/*,vite}"
.../../.node/pnpm/store/v3/tmp/dlx-55577 | +1 +
.../../.node/pnpm/store/v3/tmp/dlx-55577 | Progress: resolved 1, reused 1, downloaded 0, added 1, done
System:
OS: macOS 13.3.1
CPU: (8) arm64 Apple M1 Pro
Memory: 237.09 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.12.1 - ~/Library/pnpm/node
npm: 8.18.0 - /opt/homebrew/bin/npm
Browsers:
Brave Browser: 112.1.50.119
Firefox Developer Edition: 113.0
Safari: 16.4
npmPackages:
@sveltejs/adapter-auto: ^2.0.0 => 2.0.0
@sveltejs/kit: ^1.15.7 => 1.15.7
svelte: ^3.58.0 => 3.58.0
vite: ^4.2.2 => 4.2.2Severity
annoyance
Additional Information
No response