Missing property in type from ActionData
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 20.8k
- Forks
- 2.3k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 156
Description
Describe the bug
This is to reopen issue #6823
First of all, thanks everyone for helping with this issue, but even after upgrading to the newest sveltekit version, the bug still persists. I have updated the example repo for clearer demonstration of the bug: https://github.com/harrylaulau/sveltekittest
First issue is that when one property exist in one invalid() but not another, the type of return object with that property does not exist.
Second issue is when a property is of object type, it seems to override all other type
+page.server.ts
import { invalid, redirect } from '@sveltejs/kit';
import type { Actions } from './$types';
export const actions: Actions = {
default: async ({ request, url }) => {
if (url.searchParams.get('v') === '0') return invalid(400, { common: '1' });
if (url.searchParams.get('v') === '1') return invalid(400, { common: '2', something: '' });
if (url.searchParams.get('v') === '2') return invalid(400, { common2: 1 });
if (url.searchParams.get('v') === '3') return invalid(400, { common2: '1' });
if (url.searchParams.get('v') === '4') return invalid(400, { common2: {} });
}
};

+page.svelte

- return type with
somethingdoes not exist - return type with
common2having the string type or a number type does not exist
Reproduction
https://github.com/harrylaulau/sveltekittest
Logs
No response
System Info
System:
OS: macOS 12.6
CPU: (10) arm64 Apple M1 Max
Memory: 7.60 GB / 32.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 16.15.0 - ~/.nvm/versions/node/v16.15.0/bin/node
Yarn: 1.22.19 - ~/Library/pnpm/yarn
npm: 8.12.1 - ~/.nvm/versions/node/v16.15.0/bin/npm
Watchman: 2022.09.12.00 - /opt/homebrew/bin/watchman
Browsers:
Chrome: 105.0.5195.125
Safari: 16.0
npmPackages:
@sveltejs/adapter-auto: next => 1.0.0-next.80
@sveltejs/kit: next => 1.0.0-next.502
svelte: ^3.44.0 => 3.50.1
vite: ^3.1.0 => 3.1.3
Severity
serious, but I can work around it
Additional Information
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked reproduction and compare the generated types used by +page.server.ts and +page.svelte when invalid() returns different properties and value types. Trace how ActionData is produced and verify that the completed types retain something, common2, and their string, number, and object variants.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- backend-api-design, developer-experience
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100