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

Issue with generated SvelteKit types in VS Code #10627

Closed
michal-weglarz opened this issue Aug 25, 2023 · 2 comments
Closed

Issue with generated SvelteKit types in VS Code #10627

michal-weglarz opened this issue Aug 25, 2023 · 2 comments

Comments

@michal-weglarz
Copy link

Describe the bug

I've been having this annoying issue in VS Code, where I open a SvelteKit file (page, layout, hooks etc.) and I can see that Typescript is not working properly as some parameters are not getting their types inferred correctly, and instead I get a bunch of anys. However, if I remove the parameter and then retype in again, without any other changes whatsoever, it magically starts working just fine.

I tried to capture the issue in the recording. Do you know what might be causing the issue?

Screen.Recording.2023-08-25.at.16.18.23.mov

My app.d.ts file:

import { Session, SupabaseClient } from '@supabase/supabase-js';
import type { Database } from './types/supabase';

declare global {
	namespace App {
		interface Locals {
			supabase: SupabaseClient<Database>;
			getSession(): Promise<Session | null>;
		}
		interface PageData {
			session: Session | null;
		}
		// interface Error {}
		// interface Platform {}
	}
}

I've also tried running npx svelte-kit sync but it didn't change anything.

Reproduction

I've managed to reproduce it with the default SvelteKit demo:

  1. Create a new SvelteKit project using CLI: npm create svelte@latest my-app

    • select "SvelteKit demo app" template
    • select Typescript syntax.
  2. cd my-app && npm install and then open VS Code

  3. Create a new +page.server.ts file in src/routes/sverdle/how-to-play/ with the following content:

        export const load = ({ cookies, depends, fetch }) => {
          return {
            message: "test",
          };
        };
  4. Run the dev server: npm run dev => TYPES ARE CORRECT.

  5. Open file src/routes/sverdle/+page.server.ts in a new editor tab.

  6. Close the editor, shut down the dev server, and then reopen VS Code again.

  7. Switch to the +page.server.ts that we just added => TYPES ARE BROKEN

Sometimes, to see the wrong types, it might take up to a couple of tries of closing and reopening the editor, but regardless of that it happens very consistently.

The only way to get the appropriate types back is to remove the parameter, and then retype it again without any other modifications (I demonstrated that in the video recording above).

Logs

No response

System Info

System:
    OS: macOS 14.0
    CPU: (8) arm64 Apple M1 Pro
    Memory: 142.22 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.12.1 - ~/.nvm/versions/node/v18.12.1/bin/node
    npm: 8.19.2 - ~/.nvm/versions/node/v18.12.1/bin/npm
    pnpm: 8.6.12 - ~/Library/pnpm/pnpm
    Watchman: 2023.07.24.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 115.0.5790.102
    Safari: 17.0
  npmPackages:
    @sveltejs/adapter-auto: ^2.0.0 => 2.1.0
    @sveltejs/kit: ^1.20.4 => 1.22.4
    svelte: ^4.0.5 => 4.1.2
    vite: ^4.4.2 => 4.4.7

Severity

annoyance

Additional Information

No response

@jasonlyu123
Copy link
Member

jasonlyu123 commented Aug 26, 2023

There is a language tools problem, and there is already an issue about it.

sveltejs/language-tools#2053

It probably is a race condition. But we haven't found out the reason yet.

@ghostdevv
Copy link
Member

Will close this since it's a duplicate 🙏

@ghostdevv ghostdevv closed this as not planned Won't fix, can't repro, duplicate, stale Aug 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants