Skip to content

Conversation

@jtomaszewski
Copy link

Problem

When using createClient<any>() with placeholder or fallback OpenAPI types, TypeScript incorrectly requires the second parameter in API calls:

// With placeholder types: export type paths = any;
const client = createClient<any>({ baseUrl: '...' });

// Error: Expected 2 arguments, but got 1
client.GET('/users/me');

This is problematic in scenarios where:

  • Docker builds need to work without the actual OpenAPI spec file
  • Using placeholder/fallback types during development
  • Gradual migration to OpenAPI-based type systems

Root Cause

The RequiredKeysOf type helper doesn't properly handle the any type. When RequiredKeysOfHelper<T> evaluates to any, the current implementation doesn't recognize it as "no required keys", causing TypeScript to treat parameters as required.

Solution

Add an additional conditional check in RequiredKeysOf:

RequiredKeysOfHelper<T> extends any ? never

This ensures that when the type parameter is any, RequiredKeysOf correctly returns never, indicating no required keys. This makes the second parameter optional in API calls.

Impact

  • ✅ Fixes type errors when using createClient<any>()
  • ✅ Enables Docker builds with placeholder OpenAPI types
  • ✅ Maintains backward compatibility for all existing use cases
  • ✅ No changes to runtime behavior (types only)

Relates to #1778

@jtomaszewski jtomaszewski requested a review from a team as a code owner November 20, 2025 19:38
@jtomaszewski jtomaszewski requested a review from gzm0 November 20, 2025 19:38
@netlify
Copy link

netlify bot commented Nov 20, 2025

👷 Deploy request for openapi-ts pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit db4e2ec

@changeset-bot
Copy link

changeset-bot bot commented Nov 20, 2025

⚠️ No Changeset found

Latest commit: db4e2ec

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Use standard TypeScript pattern `0 extends 1 & T` to detect `any` type instead of broken `extends any` check.

Also fix type issue in openapi-react-query useInfiniteQuery that was exposed by this change.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@jtomaszewski jtomaszewski force-pushed the fix/required-keys-of-any-type branch from 94659ee to db4e2ec Compare January 9, 2026 16:24
@jtomaszewski
Copy link
Author

FYI I've added some tests and fixed all CI checks.

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