You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I just started moving code over to @TkDodo's [Query Options API pattern]](https://tkdodo.eu/blog/the-query-options-api). I noticed something was not invalidating, and it's because I forgot to .queryKey from my query options factory.
I would expect that invalidateQueries would validate that a queryKey needs to be an array. For some reason if queryKey: someValueThatIsOfTypeQueryOptions, it does not throw a type error. You can try out the example below.
Notice how this invalidateQueries is not throwing a type error here. This is problematic, because if you forget to .queryKey, the invalidation will not work.
// No error
queryClient.invalidateQueries({
// THIS DOES NOT SHOW A TYPE ERROR ON 5.66.9
queryKey: getTodosOptions,
});
// Should actually be
queryClient.invalidateQueries({
// THIS DOES NOT SHOW A TYPE ERROR ON 5.66.9
queryKey: getTodosOptions.queryKey,
});
Describe the bug
I just started moving code over to @TkDodo's [Query Options API pattern]](https://tkdodo.eu/blog/the-query-options-api). I noticed something was not invalidating, and it's because I forgot to
.queryKey
from my query options factory.I would expect that invalidateQueries would validate that a queryKey needs to be an array. For some reason if queryKey: someValueThatIsOfTypeQueryOptions, it does not throw a type error. You can try out the example below.
Notice how this invalidateQueries is not throwing a type error here. This is problematic, because if you forget to .queryKey, the invalidation will not work.
Your minimal, reproducible example
https://www.typescriptlang.org/play/?#code/OQVwzgpgBAxgNgSwgOwC7ANwCgsILYAOA9gE6pQDeUAjiBCQJ4DyBqCRyYANFOBAIp1GPPoPoMAwohTkAvlABmJInijAAAqgCGnbTADWAehIQtMVAFpa4zLkKlyVPgGVtqaPKUq1Js+my4aPQKZtAAKkQAJkSUWFBQCJEAXFDIIHgARvTY8WyocBApYKgkCMgA5jmwKgQF7slQGUREBTrYsjiGhlAAskQGUACCAAoAkrBacHBYMBzFihCoMAAWEdFgUAC8UFpgDMgwUAAUAJQpw8p4CJAAPGtEANoAugB8W28UcVBdUM74IHAtO4hmMoJEIICGF8tAB3LQIcjICAwqAXFTXCBHI4mMAtABuEBO7ygkFQYXwECIIFQ2IguLg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T5m-E4ss04JSra0K5LC9ezcW8cH3qBy4D+-IJ7k9q3z+MUImWs63rBtGwQJtm1SeoNlARbKapWybNsHkmSgAAfjUNbaGdBHbO0JhYaGZh9CmRSMAa2tstAm27GyYAshExz0nj7RAfsA5EiDiSRYmkVL0COAA4AJwcEyx3knQYUwN6GFPvQ6We8JYH0XkfV8J9OFnz7pfXG-N-a321rrfWhtjamx1G-S2n8KDf0fH-f+TkbKmRAUg+G4CICQJZC7SGMD3YINAfDFBaCMFYNoV7PBCACGBzeBpLSFDgBqPqNQ6xcU2EywkEBGyzDWEb1PofY+ANT7nyTkIjWojJFPxfrIi2H8v7OJIL-f+jk-HuA0aYoxECnb6OgbAgwJitE22FBYlkmDsF91sfYohjjSEpMoRk3cWSaEq28dLUYBxMkQACfwzpd1TqcxljcAEvNhH4wBmAAgoQLBoJFknCgN0wBAKtHgLQBAsQ3XqccPuNxEBQH0ERf2N1I6RHkFEkRANbRcQSO4PAYALAwBkI+YGusmgkHBKk8279IiLMXsdGZOg+5xSudfRMRYzluI-poxASILCoGWObcoq9oHmL0SUqpnivadKWWc+MEAcWjMMMC5AeL2FktBarT6kz-o3zwHAe+kiJHxOgSaDYvz5FQuSlaGF-JNHILtsgHWGCoCIOtgwCEdoYSisqVY6lFKZbLN5fy4BahfGtIbCUjKepsqYOpWtMlSrjqGEQBSjkOK1oAjYUM2a3l2hYCAA
Steps to reproduce
Paste the code above into a react app.
Expected behavior
invalidateQueries throws type error when queryKey is not of type array
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
macOS Sequoia
Tanstack Query adapter
None
TanStack Query version
5.66.9
TypeScript version
5.5.4
Additional context
No response
The text was updated successfully, but these errors were encountered: