queryCollectionOptions type error missing compareOptions/comparisonOpts
Hi, I'm pretty new working with DB, I've been working with it for about a month now all perfect and today after upgrading to the latests version of DB,
getting type errors when using queryCollectionOptions with createCollection:
Type 'Collection<T, string, any, any, any>' is missing properties:
comparisonOpts, compareOptions
These properties were added in PR #762
Currently using
as any workaround but losing all type inference.
Regarding code, it doesn't matter if I add a full working collection or a minimum example, the error shows up. The code in the first screenshot is the todos example in the JSDocs of the queryCollectionOptions for testing.
I'm adding a third image with the workaround I'm using, as any to avoid the error showing up and the type inference to get type safety again since without it I'm getting something like:
name: {} | undefined
I'm not sure if this is a "me" issue or something else.
(Thank you for this amazing library and sorry if I'm not reporting this correctly, literally my first message in the discord)


32 Replies
harsh-harlequinβ’2w ago
ah thanks for the through bug report! https://github.com/TanStack/db/pull/816
GitHub
Fix queryCollectionOptions type error after upgrade by KyleAMathews...
This fixes a TypeScript error where queryCollectionOptions (and other collection options functions) produce Collections that TypeScript reports as missing the compareOptions property.
Reported on d...
rare-sapphireβ’2w ago
I tried reproducing this type error but i couldn't:
This type checks without error. Note that i has to change your typecast to
return response.json as Promise<Todo[]> because .json() returns a promise.
@Ozmah i also posted my comment on the GH issue: https://github.com/TanStack/db/pull/816
Please reply on the GH issue as that provides better visibility for everyone interested in the bugharsh-harlequinβ’2w ago
ok so close the PR?
rare-sapphireβ’2w ago
I would close the PR but you added the fix for that other bug in it. So i would move your fix to a separate PR and then close this one (we can always reopen it if the OP comes back with an example we can reproduce)
harsh-harlequinβ’2w ago
oh changing it to
public readonly compareOptions?rare-sapphireβ’2w ago
I was proposing that, yes. But i don't see how that or claude's changes are solving the problem. Mainly, because i don't see what the problem is. I tried reproducing the type error reported here and i could not reproduce it. So i don't think there is any problem, i.e. no code changes needed?
harsh-harlequinβ’2w ago
cool, I'll just change the PR name/body
rare-sapphireβ’2w ago
Ok, but pls also remove any changes that are unrelated to this. i.e. claude's first few commits.
harsh-harlequinβ’2w ago
hmm? There's just the change from the getter to
public readonly now β https://github.com/TanStack/db/pull/816/filesGitHub
use
public readonly to make compareOptions readable but not wri...Probably fixes a typescript error.
rare-sapphireβ’2w ago
What problem does this solve?
harsh-harlequinβ’2w ago
nothing apparently β researched it again and ts treats them the same π€· closing
flat-fuchsiaOPβ’2w ago
I've been following the PR and will post back with new reproducible code as soon as I get out of work if it helps still in any way π
flat-fuchsiaOPβ’7d ago
Since the PR was closed I'm replying here. I took the code example you created and simply pasted it in two different code bases I have using DB, both times the error shows up, it doesn't create critical errors of any kind but removes the typesafety entirely.
Added two screenshots, one showing the error and one showing the code example provided previously. This is the complete stack:
- Bun
- Start
- DB
- Form
- ElysiaJS
Versions:
I'm also going to try this using the tanstack starter, installing DB from scratch and try it using npm instead of Bun.
In the meantime, is there anything in particular you'd like me to share about the codebases I've tried it in or anything in particular I can help with?
I'm on MΓ©xico's timezone and life got a bit in the way, that's why it took me so long to respond, I apologize for that.


harsh-harlequinβ’7d ago
What's the type errors?
flat-fuchsiaOPβ’7d ago
I'm sorry, what do you mean by the type errors?
harsh-harlequinβ’7d ago
like all the text the ts compiler spits out when you hover over an error β they try to tell you what the error is β we can't read the full thing from the first screenshot
flat-fuchsiaOPβ’7d ago
oh, of course give me a second and I'll paste the whole thing
harsh-harlequinβ’7d ago
one problem here is you don't pass in your schema β but it should error without a schema
harsh-harlequinβ’7d ago
GitHub
Fix TypeScript type resolution for QueryCollectionConfig when using...
Previously, the QueryCollectionConfig interface extended BaseCollectionConfig, but TypeScript failed to resolve inherited properties like getKey, onInsert, onUpdate, etc. when the interface contain...
flat-fuchsiaOPβ’7d ago
Please let me know if there's anything else I can do to help :PeepoHappy:
harsh-harlequinβ’7d ago
Did you try adding your schema?
flat-fuchsiaOPβ’7d ago
I'll move around some code to get a better example with a schema to see the results and get back to you.
harsh-harlequinβ’7d ago
I mean your screenshot above has todoSchema. You can just pass it in as your schema
flat-fuchsiaOPβ’7d ago
Oh sure what I meant is that I'm not at the computer now, I'll go back to it later tonight and I'll do that and maybe one more example.
I'm sending two different examples, one using the
todo example by @kevindp and one taken from one app I'm working on at the moment (pardon my code π
).
Note, I made a fresh installation for both the todo example and for my app to avoid any version collisions on either environment.
The first screenshot is the same todo example including the original schema provided, the error is the same, if I add the as any fix I mentioned in the original post, we can check the schema is being used (screenshot 2).
For the second example, this is a collection I'm already using:
And this is the schema:
In all my collections I've used a schema every time.
If you need me to post any of this information in the PR or any other information, please let me know, I'll be happy to help :PeepoHappy:flat-fuchsiaOPβ’7d ago


rare-sapphireβ’7d ago
@Ozmah i think your IDE might be confused. The todo code snippet compiles without (type) errors on my machine. Sometimes IntelliSense in VS Code gets confused, use the TypeScript compiler as the source of truth, if you compile it does TypeScript complain?
flat-fuchsiaOPβ’7d ago
I'll try it tomorrow morning but just in case it's relevant, this happens in vscode and zed, all screenshots I've shared are from zed mostly.
I'll give all this a go using the tanstack starter and db fresh install as well, might be related to my stack π€
rare-sapphireβ’7d ago
Yep, couldn't reproduce on my side. I'm testing it on latest version of our main branch.
flat-fuchsiaOPβ’6d ago
Hi, I've been running several tests and it seems @kevindp was right all along, this is a "me" issue, not sure how yet but it's bun related. Sorry guys for wasting your time, I'll make sure to investigate this and I'll be a lot more thorough testing the library in the future to avoid doing something like this again.
rare-sapphireβ’6d ago
No worries. It happens to all of us!
flat-fuchsiaβ’5d ago
@Ozmah did you ever figure out what was causing that error in the editor on your end. Iβm seeing it also. It compiles and seems to work correctly but I would love to fix whatever is causing it. Iβm seeing the error in cursor.
Moved
flat-fuchsiaOPβ’4d ago
Hi Dan, sorry I didn't see the message till now. So far I haven't had time to investigate in depth but I do know bun is thinking I have two versions of DB installed despite cleaning everything related to package.json or even a new installation.
I'll have time to investigate next week and if I find anything noteworthy I'll get back to you :PeepoHappy: