-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
Describe the problem
My Issue
I don't want to use the internal server of SvelteKit, just the SSR, and that's why I run a trpc + express backend, that uses primsa + kysely (more complicated generated types). When I try to use any types from the backend codebase, be it with the project reference key in tsconfig, or use it as a project dependency, the types just semi-works in Svelte Kit.
What works?
Everything works in normal .ts files, there is no error whatsoever, and I can freely use the trpc client with the imported Router type, and everything is inferred (this is not really specific to trpc, type inferrence just works, trpc is just a clear use case for the Problem im describing)
What does not really work?
+server.ts (.svelte automatically as well) cannot resolve it without the d.ts types built. Which is weird, because the normal .ts files can resolve everything, without anything being built. There is also a disconnect between the +server.ts types, and the generated type from SvelteKit: The types are complete in +page.server.ts but then cannot be resolved in the generated file, which makes it useless since .svelte files use the generated type, and I lose every type safety.
Describe the proposed solution
Right now my "fix" is to declare my backend project as a reference in the generated tsconfig.json. But this is terribble DX, since everytime the code is regenerated, I have to re add it again. I'm open to any other solution, but right now this seems to be best for my Environment. If there is no better option, I think the best idea would be to let people add a reference option for the generated code to access external projects.
Alternatives considered
I have considered just watching my backend project and build the types, but there is still the issue that the .svelte code does not instantly reflect those changes, but the normal .ts file do. Maybe this is an LSP issue, but atleast when adding the references key to the generated tsconfig.json, the changes are reflected instantly...
I can also just give up and use ts-rest with dedicated DTO, but I like the DX of trpc + sveltekit (when it works)
Importance
would make my life easier
Additional Information
I'd really like to avoid using the inbuilt server, because I want separate concerns: I want SvelteKit as my frontend, and my api to be it's own project.
Using dedicated return types at the router level doesn't change anything, no type will be resolved.
If a sample project is wanted I can quickly make one and send it, but I hope the explanation should be plenty to just know what I'm talking about.
in my backends package.json, the project is a module, with
{ main: src/index.ts, types: src/index.ts }
,