Schema Type Info Not Propagating In Svelte / VSCode
Couldn't find a similar post / issue so...
I have defined a schema like this...
...and confirmed via the dashboard that this is the schema reflected on convex's server.
I noticed as I started using useQuery() in my svelteKit app that I wasn't getting field name completion on the returned documents.
My svelte route looks like this...
...and it is definitely working in the sense that I can generate content on the page based on the reactive state of query (this is fantastic, BTW).
BUT, if I hover over
api.instance_groups.get
in VSCode, I see the type information shown in the attached screenshot.
Shouldn't that any
be the actual type of the document as defined in the schema?
Or maybe I'm barking up the wrong tree. But something means that VSCode doesn't know the types of the returned documents.9 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Ask in the <#1228095053885476985> channel to get a response from <@1072591948499664996>.
- Avoid tagging staff unless specifically instructed.
Thank you!
Looks like the problem is with VSCode. It's having trouble loading the new TS definition files generated by convex when they get updated. Restarting VS Code (or just doing a Developer: Reload Window from the command pallette) kicks it to update its definitions. I wonder if anyone else has seen this kind of behavior?
Did you remember to run npx convex dev in another console, try running it in your vscode terminal
Yes indeed. It's been running the whole time. Either VS Code doesn't pick up the filesystem changes that Convex's codegen is doing or it does but the TS LSP somehow doesn't react to them.
@btab0426 What's the operating system you're on? Now that these files exist, this does live update now correct? There's a transition from no schema to having a schema that might be the issue here, but just adding tables and columns to those tables should just work
Mac OS 14 (haven't done the Sequoia update yet). VS code 1.93.1.
I had the exact same instinct that somehow the schema transition had created too much of a leap for VS Code to grok.
I just did a test to try and reproduce. Specifically...
1. create a new model file goats.ts containing...
This initially gets a red squiggle under
"goats"
because I guess it's not one of the table names in my schema file.
Then I add the schema for that table...
And if I go back to goats.ts
the red squiggle has disappeared. So VS Code now understands the set of literal table names correctly.
Then I head over to my test svelte route and start typing api.
and it completes with the prior table names but doesn't offer goats
.
If I then restart the Svelte language server, the autocomplete now works as expected. So it's something about the build / transpilation step in Svelte ...maybe?
(and, yes I am running vite dev in the background so Svelte should be doing all the update magic associated with that process)@btab0426 Thanks for investigating! I'm curious if you see anything different if you make a point of saving these files; do you use autosave? TypeScript types will update without saving, but maybe the Svelte LSP needs the save.
Whatever you find out it'd be great to open an issue on https://github.com/get-convex/convex-svelte so this is more searchable, both so someone can add their investiagations and just so people don't feel alone in this
I don't know anything about the Svelte language server but this doesn't sound like a unique thing, if saving these files isn't enough maybe there's some config that could happen it about these changes or we should the convex CLI could modify a file to ping
I followed up there, thanks for filing. I'm deep in some other stuff for the next few days but will get to this eventually, anything else you figure out would be great to hear there.
Also any other thoughts about Svelte support! There's a channel here for discussion too https://discord.com/channels/1019350475847499849/1278420438149496952