@@ -67,9 +67,9 @@ export default defineAddon({
6767 const vitePluginName = 'paraglideVitePlugin' ;
6868 js . imports . addNamed ( ast , { imports : [ vitePluginName ] , from : '@inlang/paraglide-js' } ) ;
6969 js . vite . addPlugin ( ast , {
70- code : `${ vitePluginName } ({
71- project: './project.inlang',
72- outdir: './${ paraglideOutDir } '
70+ code : `${ vitePluginName } ({
71+ project: './project.inlang',
72+ outdir: './${ paraglideOutDir } '
7373 })`
7474 } ) ;
7575
@@ -78,7 +78,8 @@ export default defineAddon({
7878
7979 // reroute hook
8080 sv . file ( `src/hooks.${ language } ` , ( content ) => {
81- const { ast, generateCode } = parse . script ( content ) ;
81+ const { ast, generateCode, comments } = parse . script ( content ) ;
82+
8283 js . imports . addNamed ( ast , {
8384 from : '$lib/paraglide/runtime' ,
8485 imports : [ 'deLocalizeUrl' ]
@@ -87,9 +88,10 @@ export default defineAddon({
8788 const expression = js . common . parseExpression (
8889 '(request) => deLocalizeUrl(request.url).pathname'
8990 ) ;
91+
9092 const rerouteIdentifier = js . variables . declaration ( ast , {
9193 kind : 'const' ,
92- name : ' reroute' ,
94+ name : ` reroute${ language === 'ts' ? ': Reroute' : '' } ` ,
9395 value : expression
9496 } ) ;
9597
@@ -101,6 +103,18 @@ export default defineAddon({
101103 log . warn ( 'Adding the reroute hook automatically failed. Add it manually' ) ;
102104 }
103105
106+ if ( language === 'ts' ) {
107+ js . imports . addNamed ( ast , {
108+ from : '@sveltejs/kit' ,
109+ imports : [ 'Reroute' ] ,
110+ isType : true
111+ } ) ;
112+ } else {
113+ js . common . addJsDocTypeComment ( existingExport , comments , {
114+ type : "import('@sveltejs/kit').Reroute"
115+ } ) ;
116+ }
117+
104118 return generateCode ( ) ;
105119 } ) ;
106120
0 commit comments