Skip to content

Fix error type inference with conditional queries using SKIP token #69

@hirotaka

Description

@hirotaka

The test at line 198-199 has a commented-out type assertion for the error value when using conditional queries with the SKIP token and select option.

Location

packages/openapi-vue-query/test/index.test.tsx:198-199

expectTypeOf(result.data.value).toEqualTypeOf<"select(true)" | undefined>();
// TODO: fix this
// expectTypeOf(result.error.value).toEqualTypeOf<false | null>();

Problem Analysis

  1. When using SKIP token with select option, the error type inference doesn't work as expected
  2. Expected type: false | null (matching the error type from the OpenAPI schema)
  3. Actual type: Likely unknown | null or a different inferred type
  4. This suggests that the UseQueryMethod type definition doesn't properly preserve error types when select is used

Context

The test creates a conditional query:

const { result } = renderHook(() =>
  useQuery(
    false
      ? {
          ...client.queryOptions("get", "/foo"),
          select: (data) => {
            expectTypeOf(data).toEqualTypeOf<true>();
            return "select(true)" as const;
          },
        }
      : SKIP,
  ),
);

Proposed Solutions

  1. Review UseQueryMethod error type parameter:

    • Ensure error type is properly preserved when select is used
    • Check if InferSelectReturnType affects error type inference
  2. Fix error type in return type:

    • The UseQueryMethod return type (lines 94-123) should properly include the error type
    • Ensure it's not being overridden or lost in type transformations
  3. Update type definition structure:

    • Consider if Response["error"] is properly passed through all type transformations
    • Check interaction between DeepUnwrapRef and error types
  4. Alternative: Update test expectations:

    • If the current behavior is actually correct, update the test to match
    • Document why the error type differs from the schema type (last resort)

Acceptance Criteria

  • Uncomment the error type assertion line
  • Type test passes with expected error type false | null
  • Error type inference works correctly in real-world usage
  • All existing tests pass

Additional Context

This issue is related to TypeScript type compatibility between openapi-fetch response types, @tanstack/vue-query hook signatures, and Vue 3 reactivity types.

Current dependencies:

  • @tanstack/vue-query: ^5.66.0
  • openapi-fetch: ^0.14.0
  • vue: ^3.5.13

These issues likely emerged from recent updates to @tanstack/vue-query (see PR #59 which fixed some type compatibility issues but may have introduced these).

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions