kit
kit copied to clipboard
Renaming +page.js to +page.ts doesn't fix typescript issues (Module '"./$types"' has no exported member 'PageLoad'.ts(2305))
Describe the bug
When creating a +page.ts file, if one initially sets it to .js, you can't just rename the file to .ts to get it to start working. I looked high and low to fix the issue, and posted on Stack Overflow, but only removing the file and recreating it with .ts initially fixes it. Somebody commented and said I should flag this bug, so here I am.
Reproduction
Is there a ts project I can fork? I can't seem to find it.
Create a +page.svelte in routes (under any folder or root level) and create a +page.js file. Then, rename it to .ts and you'll see the error. Removing the file and recreating it as .ts from the start fixes the issue.
Logs
No response
System Info
System:
OS: macOS 12.6
CPU: (10) arm64 Apple M1 Max
Memory: 8.91 GB / 64.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 18.8.0 - /opt/homebrew/bin/node
Yarn: 1.22.18 - /usr/local/bin/yarn
npm: 8.18.0 - /opt/homebrew/bin/npm
Watchman: 2022.09.05.00 - /opt/homebrew/bin/watchman
Browsers:
Chrome: 107.0.5304.110
Safari: 16.0
npmPackages:
@sveltejs/adapter-auto: next => 1.0.0-next.88
@sveltejs/adapter-cloudflare: ^1.0.0-next.40 => 1.0.0-next.40
@sveltejs/kit: next => 1.0.0-next.551
svelte: ^3.44.0 => 3.53.1
vite: ^3.1.0 => 3.2.4
### Severity
annoyance
### Additional Information
Link to SO question:
https://stackoverflow.com/questions/74469661/sveltekit-pageload-module-not-found/74483108?noredirect=1#comment131604014_74483108
~From your SO post I assume by "to get it working" you mean "to get the types working".~ (The post title says the issue is with types.)
I can't reproduce - when creating a +page.js file Kit generates the types for PageLoad, so when I rename the file to +page.ts, it picks up on them instantly. If that doesn't work for you, saving the file should fix it. Alternatively, you can restart your Typescript Language Server. Assuming you're using VSCode you can do that by opening the Command Palette and running TypeScript: Restart TS Server while having a .ts file open.
Yes - I mean the error. To get it working = to remove the error in the file
I tried saving the file, restarting all servers, etc. The only thing that helped was deleting the file and creating it with the proper extension. Interesting. The person on SO recommended I post here, which is why I did.
Interesting!
I tried reproducing this in an existing project for about 15 minutes before making my original comment. This time I created a new project with npm init svelte and tried to get it to happen for another 15, but all seems to be working fine. When I create a +page.js or +page.ts file, Kit generates the typedefs instantly, and when I rename the file to .ts and change the type syntax, it all works.
Does this still happen in your project, or is it a one-time-computer-doing-whatever-it-wants type thing? If so, can you make a new project with npm init svelte (selecting the Typescript option) and check if it's also the case there?
To make reproductions, refer to this section of a video by Rich: https://youtu.be/dB_YjuAMH3o?t=1639 Using npm over pnpm or yarn is preferable because everyone has npm.
I will check tomorrow and get back to you 😎👍
Closing due to inactivity and lack of reproduction