Skip to content

refactor: use generic constraints to fix @cloudflare/workers-types version conflicts#48

Open
imjlk wants to merge 4 commits intozpg6:mainfrom
imjlk:fix/cloudflare-types-compatibility-v2
Open

refactor: use generic constraints to fix @cloudflare/workers-types version conflicts#48
imjlk wants to merge 4 commits intozpg6:mainfrom
imjlk:fix/cloudflare-types-compatibility-v2

Conversation

@imjlk
Copy link
Contributor

@imjlk imjlk commented Feb 2, 2026

Problem

Type mismatch errors occur when users have a different version of @cloudflare/workers-types than the library expects, particularly in monorepos or projects with multiple Cloudflare dependencies.

Solution

Introduced generic constraint interfaces (KVNamespaceConstraint, R2BucketConstraint) that define only the methods the library actually needs. Made withCloudflare and related types generic to accept any compatible KV/R2 types from user projects.

Before:

// Hard dependency on specific @cloudflare/workers-types version
import type { KVNamespace } from "@cloudflare/workers-types";
kv?: KVNamespace<string>;

After:

// Accepts any compatible type via generics
export interface KVNamespaceConstraint {
  get(key: string, options?: ...): Promise<string | null>;
  put(key: string, value: ..., options?: ...): Promise<void>;
  delete(key: string): Promise<void>;
}
kv?: TKV;  // Auto-inferred from user's types

Result

Users can now pass platform.env bindings directly without type errors. Types are automatically inferred:

withCloudflare({
  kv: platform.env.MY_KV  // ✅ Types inferred from your @cloudflare/workers-types
}, ...)

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 2, 2026

Open in StackBlitz

npm i https://pkg.pr.new/zpg6/better-auth-cloudflare@48

commit: baa382f

@imjlk imjlk force-pushed the fix/cloudflare-types-compatibility-v2 branch from 8d20d79 to baa382f Compare February 14, 2026 09:13
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