Open ohmree opened 10 months ago
Hello @ohmree, that's a very good catch. We use esbuild to clean-up the code extracted from the loader, which strips the TS annotation here https://github.com/Hebilicious/form-actions-nuxt/blob/1d99f9bf7b20001977a64df8433c2a3dd2ad141d/packages/form-actions-nuxt/src/module.ts#L29
That is overkill and we shouldn't really bother doing that, as when you build the project, the production files will be properly minified anyways. But the main issue that I have would be that these generated files could contain a bunch of duplicated logic. Not the end of the world, but I would prefer if we had a better way to properly extract each loader from the source files.
Would it not be possible for the generated foo.get.ts
to cast its export usingas typeof import('/path/to/foo').loader
or something along those lines?
Not the cleanest but I can't see why it won't work as a quick and dirty fix.
And have you looked at how sveltekit handles type safety for loaders and actions? Do you think it could be applicable here?
Would it not be possible for the generated
foo.get.ts
to cast its export usingas typeof import('/path/to/foo').loader
or something along those lines? Not the cleanest but I can't see why it won't work as a quick and dirty fix.And have you looked at how sveltekit handles type safety for loaders and actions? Do you think it could be applicable here?
Hopefully there's no need for that, as we use magicast to extract the loaders from the source files, it should just copy the loader from your source file and keep the TS annotations.
If that's not working, unfortunately we'll have to add some custom parsing to properly extract them from the source files.
Environment
Reproduction
https://github.com/ohmree/reimagined-giggle
Describe the bug
In
server/actions/foo.ts
I pass a type parameter togetQuery
which seems to be erased from the generatedserver/.generated/.loader/foo.get.ts
.This causes volar to infer the type of
result.id
inpages/foo/[id].vue
as astring | number | boolean | QueryValue[] | Record<string, any> | QueryValue[]
, which results in type errors for seemingly correct code.Additional context
Trying to cast
id
in any other way before returning it from the loader seems to result in the same.Also if I manually apply the type annotations from my source file to the generated file then typescript stops complaining.
Logs
No response