-
-
Notifications
You must be signed in to change notification settings - Fork 578
Closed
Labels
bugSomething isn't workingSomething isn't workingswr-openapiRelevant to swr-openapi libraryRelevant to swr-openapi library
Description
swr-openapi version
5.3.1
Description
The current implementation of createQueryHook
and createInfiniteHook
doesn't enforce exact object literal validation for query and path parameters, allowing invalid properties to pass TypeScript compilation without errors.
This leads to runtime issues and reduces the type safety benefits that developers expect from a TypeScript-first OpenAPI integration.
Reproduction
import createClient from 'openapi-fetch';
import { createQueryHook } from 'swr-openapi';
import type { paths } from './generated'; // From openapi-typescript
const client = createClient<paths>();
const useQuery = createQueryHook(client, 'api');
// ❌ This should cause a TypeScript error but doesn't
const { data } = useQuery('/pets', {
params: {
query: {
limit: 10,
invalid_property: 'should error', // No TypeScript error!
},
},
});
// ❌ Same issue with infinite queries
const useInfiniteQuery = createInfiniteHook(client, 'api');
const { data: infiniteData } = useInfiniteQuery('/pets', pageIndex => ({
params: {
query: {
limit: 10,
another_invalid_prop: 'also no error', // No TypeScript error!
},
},
}));
Expected result
Expected behavior: TypeScript should show compilation errors for invalid_property
and another_invalid_prop
.
Actual behavior: Code compiles without errors, potentially causing runtime issues.
Extra
- I’m willing to open a PR (see CONTRIBUTING.md)
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingswr-openapiRelevant to swr-openapi libraryRelevant to swr-openapi library