Skip to content

Conversation

@jacekradko
Copy link
Member

Summary

  • Change SignOut type from overloaded interface to union parameter type for better TypeScript structural compatibility
  • Add ClerkProviderValue type that IsomorphicClerk can properly satisfy
  • Update ClerkContextProvider to accept ClerkProviderValue instead of Clerk
  • Remove @ts-expect-error suppression from ClerkProvider

Problem

The ClerkProvider component had a @ts-expect-error comment suppressing a type mismatch between IsomorphicClerk and the expected Clerk type. This was caused by:

  1. Function overloads: The SignOut interface used TypeScript function overloads, which cannot be structurally matched against a single function implementation
  2. Void returns: IsomorphicClerk wraps methods to allow void returns (for pre-mount queuing), making it incompatible with Clerk
  3. Optional properties: IsomorphicClerk has client, billing, apiKeys as optional

Solution

Option A: Fix SignOut type

Changed from overloaded interface to union parameter type - API compatible but structurally matchable:

// Before (overloads)
export interface SignOut {
  (options?: SignOutOptions): Promise<void>;
  (signOutCallback?: SignOutCallback, options?: SignOutOptions): Promise<void>;
}

// After (union params)
export type SignOut = (
  optionsOrCallback?: SignOutOptions | SignOutCallback,
  options?: SignOutOptions,
) => Promise<void>;

Option C: Define explicit provider type

Created ClerkProviderValue type in @clerk/shared/types that:

  • Allows methods to return void (for pre-mount queuing in IsomorphicClerk)
  • Makes client, billing, apiKeys optional
  • Omits internal browser-specific methods that IsomorphicClerk doesn't implement

This creates an explicit, documented type boundary at ClerkContextProvider.

Type Flow

Clerk (base interface, strict return types)
  ↓
LoadedClerk (extends Clerk, guarantees client)
  ↓
ClerkProviderValue (allows void returns, optional props, omits internal methods)
  ↓
IsomorphicClerk (implements ClerkProviderValue ✓)
  ↓
ClerkContextProvider (accepts ClerkProviderValue, casts to LoadedClerk)
  ↓
ClerkInstanceContext<LoadedClerk> (consumers get strict types)

Test plan

  • pnpm build --filter @clerk/shared passes
  • pnpm build --filter @clerk/react passes
  • pnpm test --filter @clerk/shared - 952 tests pass
  • pnpm test --filter @clerk/react - 340 tests pass
  • TypeScript type checking passes without errors

- Change SignOut type from overloaded interface to union parameter type
  for better TypeScript structural compatibility
- Add ClerkProviderValue type that IsomorphicClerk can satisfy
- Update ClerkContextProvider to accept ClerkProviderValue
- Remove @ts-expect-error from ClerkProvider

The SignOut type previously used function overloads which TypeScript
cannot structurally match against a single function implementation.
Changing to union parameters maintains API compatibility while fixing
the type mismatch.

ClerkProviderValue is a relaxed version of Clerk that:
1. Allows methods to return void (for pre-mount queuing)
2. Makes client, billing, apiKeys optional
3. Omits internal browser-specific methods

This creates an explicit type boundary at ClerkContextProvider where
the cast to LoadedClerk is documented and justified.
@vercel
Copy link

vercel bot commented Feb 2, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
clerk-js-sandbox Ready Ready Preview, Comment Feb 2, 2026 2:18am

Request Review

@changeset-bot
Copy link

changeset-bot bot commented Feb 2, 2026

⚠️ No Changeset found

Latest commit: abecf9a

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants