Skip to content

Commit c957bff

Browse files
committed
fix: resolve Vue template TypeScript errors for useQuery
- Add intersection type to UseQueryMethod return type for template compatibility - Enable direct property access in Vue templates (data.title, error.message) - Maintain Vue Query v5 compatibility while improving TypeScript experience - Fix issues with noUncheckedIndexedAccess strict configuration
1 parent cd12103 commit c957bff

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"openapi-vue-query": patch
3+
---
4+
5+
Fix Vue template TypeScript compatibility for useQuery
6+
7+
- Update UseQueryMethod return type to include unwrapped data and error properties
8+
- Enables direct property access in Vue templates (e.g., `{{ data.title }}`, `{{ error.message }}`)
9+
- Maintains compatibility with Vue Query v5 while providing better TypeScript experience
10+
- Resolves type errors when using noUncheckedIndexedAccess in strict TypeScript configurations

packages/openapi-vue-query/src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import type {
2222
} from "openapi-fetch";
2323
import type { HttpMethod, MediaType, PathsWithMethod, RequiredKeysOf } from "openapi-typescript-helpers";
2424
import type { DeepUnwrapRef, MaybeRefDeep } from "./utils";
25+
import type { Ref, UnwrapRef } from "vue";
2526

2627
// Helper type to dynamically infer the type from the `select` property
2728
type InferSelectReturnType<TData, TSelect> = TSelect extends (data: TData) => infer R ? R : TData;
@@ -111,7 +112,10 @@ export type UseQueryMethod<Paths extends Record<string, Record<HttpMethod, {}>>,
111112
...[init, options, queryClient]: RequiredKeysOf<Init> extends never
112113
? [InitWithUnknowns<Init>?, Options?, QueryClient?]
113114
: [InitWithUnknowns<Init>, Options?, QueryClient?]
114-
) => UseQueryReturnType<InferSelectReturnType<Response["data"], Options["select"]>, Response["error"]>;
115+
) => UseQueryReturnType<InferSelectReturnType<Response["data"], Options["select"]>, Response["error"]> & {
116+
data: InferSelectReturnType<Response["data"], Options["select"]> | undefined;
117+
error: Response["error"] | null;
118+
};
115119

116120
export type UseInfiniteQueryMethod<Paths extends Record<string, Record<HttpMethod, {}>>, Media extends MediaType> = <
117121
Method extends HttpMethod,

0 commit comments

Comments
 (0)