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

When RequiredKeysOfHelper<T> evaluates to 'any' (e.g., when T is 'any'),
RequiredKeysOf should return 'never' to indicate no required keys.

This fixes the issue where using createClient<any>() with placeholder
OpenAPI types would incorrectly require the second parameter in API calls
like client.GET('/path').

The fix adds an additional conditional check:
RequiredKeysOfHelper<T> extends any ? never

This ensures that when paths type is 'any' (common when using placeholder
types or fallback schemas), the second parameter becomes optional, allowing
builds to succeed without type errors.
@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 94659ee

@changeset-bot
Copy link

changeset-bot bot commented Nov 20, 2025

⚠️ No Changeset found

Latest commit: 94659ee

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

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