[PR #8155] [MERGED] fix: access control indexing type #7785

Closed
opened 2026-03-13 13:49:08 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8155
Author: @YevheniiKotyrlo
Created: 2/25/2026
Status: Merged
Merged: 3/3/2026
Merged by: @himself65

Base: canaryHead: fix/type-declaration-bugs


📝 Commits (2)

  • 8e062fc fix(types): remove zod/v4/core re-export and fix access control indexing
  • e0036d5 Merge branch 'canary' into fix/type-declaration-bugs

📊 Changes

5 files changed (+10 additions, -8 deletions)

View changed files

📝 packages/better-auth/src/plugins/access/types.ts (+2 -0)
📝 packages/better-auth/src/plugins/admin/client.ts (+2 -2)
📝 packages/better-auth/src/plugins/admin/routes.ts (+2 -2)
📝 packages/better-auth/src/plugins/organization/client.ts (+2 -2)
📝 packages/better-auth/src/plugins/organization/organization.ts (+2 -2)

📄 Description

Summary

Two source-level type fixes for consumers with skipLibCheck: false:

1. Remove zod/v4/core re-export from src/index.ts

The line export type * from "zod/v4/core" overlaps with export type * from "zod/v4" and leaks internal Zod types into the public API namespace. This causes TS2742 ("cannot be named without a reference to zod/v4/core") for consumers. The line already has @ts-expect-error above it, confirming it was known to be problematic.

Related: #5574, #4837

2. Fix access control [key][number] indexing in admin and organization plugins

The emitted .d.ts for permission types uses S[key][number] double-indexing, but TypeScript cannot narrow the intermediate [key] access to readonly unknown[] after the conditional check. This produces type errors in the emitted declarations for both admin and organization plugin client types.

Fix: introduce an ArrayElement<T> helper type (T extends readonly (infer E)[] ? E : never) and use ArrayElement<S[key]> instead of S[key][number] in 4 locations (admin/client.ts, admin/routes.ts, organization/client.ts, organization/organization.ts).

Related: #4804, #6491, #6127

Impact

  • Runtime: Zero — types only, no behavioral changes
  • Build: pnpm typecheck, pnpm lint, pnpm build all pass
  • Consumers: Fixes TS2742 and access control type errors for projects using skipLibCheck: false

Verification

  • pnpm typecheck — zero errors
  • pnpm lint (Biome, 1386 files) — no issues
  • pnpm build (tsdown, 673 output files) — clean in ~1100ms

Summary by cubic

Fix TypeScript declaration issues by removing the zod/v4/core type re-export and using a new ArrayElement helper for permission arrays. This resolves TS2742 and permission type errors for projects using skipLibCheck: false.

  • Bug Fixes
    • Removed export type * from "zod/v4/core" to prevent internal Zod types leaking and “cannot be named” errors.
    • Added ArrayElement helper in access/types and used it in admin and organization permission types (replacing S[key][number]) to fix emitted d.ts.

Written for commit e0036d5a45. Summary will update on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/8155 **Author:** [@YevheniiKotyrlo](https://github.com/YevheniiKotyrlo) **Created:** 2/25/2026 **Status:** ✅ Merged **Merged:** 3/3/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `fix/type-declaration-bugs` --- ### 📝 Commits (2) - [`8e062fc`](https://github.com/better-auth/better-auth/commit/8e062fc6eeb010393c05a9c88c1c23426eabaa62) fix(types): remove zod/v4/core re-export and fix access control indexing - [`e0036d5`](https://github.com/better-auth/better-auth/commit/e0036d5a45b0fe7ad77a84d5388972112524580c) Merge branch 'canary' into fix/type-declaration-bugs ### 📊 Changes **5 files changed** (+10 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/access/types.ts` (+2 -0) 📝 `packages/better-auth/src/plugins/admin/client.ts` (+2 -2) 📝 `packages/better-auth/src/plugins/admin/routes.ts` (+2 -2) 📝 `packages/better-auth/src/plugins/organization/client.ts` (+2 -2) 📝 `packages/better-auth/src/plugins/organization/organization.ts` (+2 -2) </details> ### 📄 Description ## Summary Two source-level type fixes for consumers with `skipLibCheck: false`: ### 1. Remove `zod/v4/core` re-export from `src/index.ts` The line `export type * from "zod/v4/core"` overlaps with `export type * from "zod/v4"` and leaks internal Zod types into the public API namespace. This causes TS2742 ("cannot be named without a reference to zod/v4/core") for consumers. The line already has `@ts-expect-error` above it, confirming it was known to be problematic. Related: #5574, #4837 ### 2. Fix access control `[key][number]` indexing in admin and organization plugins The emitted `.d.ts` for permission types uses `S[key][number]` double-indexing, but TypeScript cannot narrow the intermediate `[key]` access to `readonly unknown[]` after the conditional check. This produces type errors in the emitted declarations for both admin and organization plugin client types. Fix: introduce an `ArrayElement<T>` helper type (`T extends readonly (infer E)[] ? E : never`) and use `ArrayElement<S[key]>` instead of `S[key][number]` in 4 locations (admin/client.ts, admin/routes.ts, organization/client.ts, organization/organization.ts). Related: #4804, #6491, #6127 ## Impact - **Runtime:** Zero — types only, no behavioral changes - **Build:** `pnpm typecheck`, `pnpm lint`, `pnpm build` all pass - **Consumers:** Fixes TS2742 and access control type errors for projects using `skipLibCheck: false` ## Verification - `pnpm typecheck` — zero errors - `pnpm lint` (Biome, 1386 files) — no issues - `pnpm build` (tsdown, 673 output files) — clean in ~1100ms <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fix TypeScript declaration issues by removing the zod/v4/core type re-export and using a new ArrayElement helper for permission arrays. This resolves TS2742 and permission type errors for projects using skipLibCheck: false. - **Bug Fixes** - Removed export type * from "zod/v4/core" to prevent internal Zod types leaking and “cannot be named” errors. - Added ArrayElement helper in access/types and used it in admin and organization permission types (replacing S[key][number]) to fix emitted d.ts. <sup>Written for commit e0036d5a45b0fe7ad77a84d5388972112524580c. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 13:49:08 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#7785