Skip to content

Fix type error in generated Paraglide hook #671

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sfirrin
Copy link

@sfirrin sfirrin commented Aug 15, 2025

Motivation

When creating a new project with Paraglide and TS, the generated src/hooks.ts file has a type error:
screenshot of VS Code where there's a type error underlining the request param

I was able to fix it in my own project by following the Paraglide docs to add the reroute: Reroute type

Change

This change checks for TS and conditionally imports and adds the type

Testing

Creating a new project using the locally built dist/bin.js with TS and Paraglide generates a hooks.ts file equivalent to the Paraglide doc with no type error:

import type { Reroute } from '@sveltejs/kit';
import { deLocalizeUrl } from '$lib/paraglide/runtime';

export const reroute: Reroute = (request) => deLocalizeUrl(request.url).pathname;

Creating a new project with Paraglide in JS keeps the existing behavior:

import { deLocalizeUrl } from '$lib/paraglide/runtime';

export const reroute = (request) => deLocalizeUrl(request.url).pathname;

Running the Paraglide test passes:

➜  cli-sfirrin-fork git:(fix/add-type-to-paraglide-reroute) pnpm vitest run packages/addons/_tests/paraglide/test.ts

 RUN  v4.0.0-beta.6 /Users/swf/projects/sveltejs/cli-sfirrin-fork

 ✓  addons  _tests/paraglide/test.ts (2 tests) 11810ms
   ✓ core - kit-js  11571ms
   ✓ core - kit-ts  10964ms

 Test Files  1 passed (1)
      Tests  2 passed (2)
   Start at  10:46:22
   Duration  14.19s (transform 957ms, setup 0ms, collect 1.31s, tests 11.81s, environment 0ms, prepare 73ms)

Please let me know if there's anything more to test

Copy link

pkg-pr-new bot commented Aug 16, 2025

Open in StackBlitz

npx https://pkg.pr.new/sveltejs/cli/sv@671
npx https://pkg.pr.new/sveltejs/cli/svelte-migrate@671

commit: 9fabfb0

@manuel3108
Copy link
Member

Thanks for your pr and detailed explanations. Could you please elaborate on how to replicate the problem initially? For me running npx sv create and npx sv add paraglide produces this file:
image
Which is different from what you are reporting. And the error for $lib/paraglide/runtime goes away instantly as soon as you run pnpm dev.

Could you also confirm that you are using up to date svelte, typescript packages and a current svelte vs code extension?

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

Successfully merging this pull request may close these issues.

2 participants