Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated ActionData type from './$types' is always unknown #6631

Closed
harrylaulau opened this issue Sep 7, 2022 · 5 comments · Fixed by #6748
Closed

Generated ActionData type from './$types' is always unknown #6631

harrylaulau opened this issue Sep 7, 2022 · 5 comments · Fixed by #6748

Comments

@harrylaulau
Copy link

Describe the bug

I tried to migrate my project to the newest sveltekit version but the ActionData type imported from './$types' is always unknown.

I then tried to reproduce the issue by creating a new project from scratch and the result is the same. I edited +page.svelte and added a +page.server.ts as follows.

+page.svelte
CleanShot 2022-09-07 at 09 33 03

+page.server.ts
CleanShot 2022-09-07 at 09 29 51

The error at the script tag complains another error, still I am not sure if that is related.
CleanShot 2022-09-07 at 09 32 03

Reproduction

Git Repository

https://github.com/harrylaulau/sveltekittest

Steps

  1. created with:
    npm create svelte@latest test
    Options: skeleton project, typescript, eslint, prttier enabled.
    CleanShot 2022-09-07 at 09 46 21

  2. Edited Files:
    src/routes/+page.svelte

<script lang="ts">
	import type { ActionData } from './$types';
	export let form: ActionData;
	$: console.log(form?.success);
</script>

<h1>Welcome to SvelteKit</h1>
<p>Visit <a href="https://kit.svelte.dev">kit.svelte.dev</a> to read the documentation</p>
<form method="POST">
	<button>Log in</button>
</form>

src/routes/+page.server.ts

import type { Actions } from './$types';
export const actions: Actions = {
	default: async () => {
		return { success: true };
	}
};

Logs

console.log successfully output true when the form button is pressed

System Info

System:
    OS: macOS 12.5.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 4.19 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.08.15.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 104.0.5112.101
    Safari: 15.6.1
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.71 
    @sveltejs/kit: next => 1.0.0-next.475 
    svelte: ^3.44.0 => 3.50.0 
    vite: ^3.1.0 => 3.1.0

Severity

serious, but I can work around it

Additional Information

This is from the generated $types.d.ts file. Not sure if this screen shot is helpful.
CleanShot 2022-09-07 at 09 43 24

@harrylaulau
Copy link
Author

Further testing by adding a if branch in actions.default returning a invalid()changes the return type of actions.default in generated $types.d.ts to Promise<any>

+page.server.ts
CleanShot 2022-09-07 at 10 01 51

Generated $types.d.ts
CleanShot 2022-09-07 at 10 01 30

@harrylaulau harrylaulau closed this as not planned Won't fix, can't repro, duplicate, stale Sep 7, 2022
@harrylaulau harrylaulau reopened this Sep 7, 2022
@mattcroat
Copy link
Contributor

mattcroat commented Sep 7, 2022

I opened a discussion recently for #6597 which is interesting because it seems it's the same problem but now moved to ActionData.

@jeppech
Copy link

jeppech commented Sep 9, 2022

I think it's worth noting, that doing the same thing in a JS project, will work as expected. I've included both TS and a JS sample in #6668.

@aloker
Copy link
Contributor

aloker commented Sep 9, 2022

It's there any update on this? Do you need more input or better repos?

dummdidumm added a commit that referenced this issue Sep 12, 2022
@dummdidumm dummdidumm mentioned this issue Sep 12, 2022
5 tasks
@williamviktorsson
Copy link
Contributor

Thanks for the fix! The development experience when the types work is amazing 😍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants