feat: add QueryKeyOptions type with strict generic to getXxxQueryKey functions#3424
feat: add QueryKeyOptions type with strict generic to getXxxQueryKey functions#3424
QueryKeyOptions type with strict generic to getXxxQueryKey functions#3424Conversation
|
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
…ict query invalidation Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com>
{ strict: false } support to getXxxQueryKey functions
|
@copilot This is wrong. Strict false shouldn't be bolted onto the type union for every query key. It should simply be a part of the options type. We might need a separate options type for TanStack Query/Pinia Colada on top of SDK. Strict false should also convert every parameter into optional, eg. if path parameters were required with foo and bar inside required too, strict false would make all optional, so it's possible to supply path parameters with only foo without bar complaining that it's missing. Your initial attempt doesn't support this at all, ie. it's completely wrong |
… support and deep partials Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com>
Reworked in b5ab58f. Instead of bolting export type QueryKeyOptions<TOptions extends Options> = TOptions | ({
[K in keyof Omit<TOptions, 'url'>]?: TOptions[K] extends object ? Partial<TOptions[K]> : TOptions[K]
} & {
strict: false;
});Required-data operations now use |
{ strict: false } support to getXxxQueryKey functionsQueryKeyOptions type with strict: false support to getXxxQueryKey functions
|
@copilot I'm surprised you didn't use |
…g and strict: true support Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com>
Updated in 4440c4c. export type QueryKeyOptions<TOptions extends Options, TStrict extends boolean = true> =
TStrict extends false
? { [K in keyof Omit<TOptions, 'url'>]?: TOptions[K] extends object ? Partial<TOptions[K]> : TOptions[K] } & { strict: false }
: TOptions & { strict?: true };
export const callWithDefaultParametersQueryKey = <TStrict extends boolean = true>(
options: QueryKeyOptions<Options<CallWithDefaultParametersData>, TStrict>
) => createQueryKey(...)All three cases are now valid:
|
QueryKeyOptions type with strict: false support to getXxxQueryKey functionsQueryKeyOptions type with strict generic to getXxxQueryKey functions
|
@copilot type casting like this shouldn't be necessary: export const typesQueryKey = <TStrict extends boolean = true>(options: QueryKeyOptions<Options<TypesData>, TStrict>) => createQueryKey('types', options as Options<TypesData>);it should be possible to generate code like this: export const typesQueryKey = <TStrict extends boolean = true>(options: QueryKeyOptions<Options<TypesData>, TStrict>) => createQueryKey('types', options); |
…ic type arg Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com>
Fixed in 5b41079. The cast is gone — // before
createQueryKey('types', options as Options<TypesData>)
// after
createQueryKey<Options<TypesData>>('types', options) |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #3424 +/- ##
==========================================
- Coverage 39.16% 39.09% -0.07%
==========================================
Files 474 474
Lines 17363 17403 +40
Branches 5246 5250 +4
==========================================
+ Hits 6800 6804 +4
- Misses 8490 8524 +34
- Partials 2073 2075 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@copilot you need to update generated examples to make the CI pass: |
Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com>
|
@copilot finally, we get to the CI checks testing types. And they fail. So your fix is not working. Make sure the CI checks would pass |
…hecks Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com>
Fixed in b9dbe59. The root cause was that TypeScript couldn't infer Two fixes:
All examples now typecheck cleanly. |
QueryKeyOptions<TOptions, TStrict>utility type withstrictgenericascast — use explicit type argcreateQueryKey<Options<T>>(...)insteadcreateQueryKeycalls (tanstack + pinia)queryOptions.tsinlinecreateQueryKeycalls (whenqueryKeys.enabled = false)Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.