Generated RequestHandler
and Load
types in TypeScript
#4571
chasewalden
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've been busy and it's been a little bit since I've looked at SvelteKit. I thought I'd check out the latest features the other day and was really happy with some of the changes. The parameter matching and named layouts awesome!
The other new feature was the type generation. I didn't realize how verbose my code was getting until this change rolled out. The only downside (at least at the moment) is that
svelte dev
doesn't appear to also sync the types, nor does it clean out any generated type definition files when I inevitably decide to delete or rename a page because I didn't like the folder structure. Not really a huge issue to delete the folder and re-run it manually, but that would take a whole 10 keystrokes that I could have used to see if TC39 Temporal landed yet (it hasn't).I really like the type generation, but it feels a little odd to use in TypeScript. For whatever reason, the JSDoc type imports didn't seem to work and the types still just resolved to
any
. Even if it did work, I just know that in the back of my head I'd be thinking:I knew there had to be another way...
I first tried to just transcribe the doc comment into an
import type
statement, but I was presented with an error.After several minutes of asking GitHub Copilot existential questions in a comment and receiving semi-intelligible responses, I realized that I still have one more trick up my sleeve: abusing module resolution.
By adding
.d
to the end of the import, I was able to beat the compiler at its own game.It's not a bug, it's a feature. Being technically correct means you're still correct 😄
Joking aside, I thought this might be useful to others. Apologies in advance for the long-winded, semi-serious post. It's been a long week and I hope anyone else in the same boat can at least cap off their week with a chuckle
Beta Was this translation helpful? Give feedback.
All reactions