Skip to content

fix(typescript): derive context enabled type from UseQueryOptions#345

Open
SchulteDev wants to merge 1 commit into
fabien0102:mainfrom
SchulteDev:fix/derive-enabled-from-usequeryoptions
Open

fix(typescript): derive context enabled type from UseQueryOptions#345
SchulteDev wants to merge 1 commit into
fabien0102:mainfrom
SchulteDev:fix/derive-enabled-from-usequeryoptions

Conversation

@SchulteDev

@SchulteDev SchulteDev commented Jun 29, 2026

Copy link
Copy Markdown

Problem

The React-Query context template hardcodes the exported react-query type name Enabled:

plugins/typescript/src/templates/context.ts

import { /* ... */ type Enabled /* ... */ } from '@tanstack/react-query';
// ...
enabled?: Enabled<TQueryFnData, TError, TQueryFnData, TQueryKey>;

TanStack Query renamed this exported type EnabledQueryBooleanOption in v5.100.0. The underlying definition is unchanged — it's purely a rename of the exported alias:

boolean | ((query: Query<TQueryFnData, TError, TData, TQueryKey>) => boolean)
@tanstack/react-query exported type
≤ 5.99.x Enabled
≥ 5.100.0 QueryBooleanOption

As a result, the generated context file fails to type-check for anyone on react-query ≥ 5.100.0, because Enabled no longer exists.

Why not just rename to QueryBooleanOption?

A straight swap would simply move the breakage: it fixes ≥ 5.100.0 consumers but breaks everyone on < 5.100.0, where QueryBooleanOption doesn't exist. Since the package declares no react-query peer range, nothing enforces a minimum version, so a hardcoded alias name is fragile in either direction — and this could recur on the next rename.

Fix

Derive the field structurally from UseQueryOptions (already imported in this template) instead of referencing the alias name at all:

enabled?: UseQueryOptions<TQueryFnData, TError, TQueryFnData, TQueryKey>['enabled'];

This resolves to whatever react-query types enabled as, across every v5 version, and is immune to future renames of the alias. The type Enabled import is removed.

Changes

  • plugins/typescript/src/templates/context.ts: drop the Enabled import; type the enabled field via UseQueryOptions<...>['enabled'].
  • examples/frontend/src/github/githubContext.ts: regenerated snapshot (the only generated diff is the enabled?: line + dropped import).

Testing

  • @openapi-codegen/typescript suite: 229 tests pass.
  • Verified the generated context file type-checks against both @tanstack/react-query@5.66.0 (pre-rename) and @tanstack/react-query@5.101.2 (post-rename, confirming Enabled is gone there yet the structural form still compiles).

@SchulteDev SchulteDev force-pushed the fix/derive-enabled-from-usequeryoptions branch from 5356fc4 to c842782 Compare June 29, 2026 17:18
TanStack Query renamed the exported type `Enabled` -> `QueryBooleanOption`
in v5.100.0, so the generated context file fails to type-check on
react-query >= 5.100.0 where `Enabled` no longer exists.

Instead of swapping to the new alias (which would just break < 5.100.0),
derive the field structurally from `UseQueryOptions` (already imported):

    enabled?: UseQueryOptions<TQueryFnData, TError, TQueryFnData, TQueryKey>['enabled'];

This resolves to whatever react-query types `enabled` as across every v5
version and is immune to future renames of the alias. The `type Enabled`
import is dropped and the github example snapshot is updated accordingly.

Verified the generated context type-checks against both react-query
5.66.0 (pre-rename) and 5.101.2 (post-rename).
@SchulteDev SchulteDev force-pushed the fix/derive-enabled-from-usequeryoptions branch from c842782 to 76b4e18 Compare June 29, 2026 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant