[PR #8701] [MERGED] fix(oauth-provider): fix dist declaration type errors #25058

Closed
opened 2026-04-15 22:42:34 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8701
Author: @gustavovalverde
Created: 3/20/2026
Status: Merged
Merged: 3/20/2026
Merged by: @himself65

Base: canaryHead: fix/oauth-provider-dist-types


📝 Commits (1)

  • 554d0b5 fix(oauth-provider): fix dist declaration type errors

📊 Changes

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

View changed files

📝 packages/oauth-provider/src/client-resource.ts (+5 -2)
📝 packages/oauth-provider/src/consent.ts (+1 -1)
📝 packages/oauth-provider/src/register.ts (+1 -1)
📝 packages/oauth-provider/src/utils/index.ts (+1 -1)

📄 Description

Summary

The oauth-provider package has 8 type errors in its emitted .d.mts declarations that are invisible during development but break external consumers. This PR fixes them and adds CI validation to prevent regressions.

Why these errors are hidden

The monorepo uses customConditions: ["dev-source"] in tsconfig.base.json, which resolves workspace imports to source .ts files instead of built dist/ output:

// tsconfig.base.json
"customConditions": ["dev-source"]

Each package exports a dev-source condition:

"dev-source": "./src/index.ts"

So pnpm typecheck (root tsc --build) resolves all cross-package imports to source — types are always consistent. But the published dist declarations have real type issues.

Scenario What TypeScript sees Result
Root tsc --build Source .ts via dev-source Passes
Package-level tsc --noEmit Source with dist deps (no build mode) 8 errors
External consumer via npm Dist .d.mts files Broken types

Commit 1: Fix the 8 type errors

  1. client-resource.ts (5 errors) — auth?.options.baseURL typed as BaseURLConfig (includes DynamicBaseURLConfig) in dist. Fix: narrow to string | undefined with a typeof check.

  2. consent.ts (1 error) — ctx.context.postLogin doesn't exist on dist AuthContext (dynamically added at runtime). Fix: cast to Record<string, unknown>.

  3. register.ts (1 error) — redirect_uris typed as string[] | undefined in dist, assigned to string[]. Fix: default to [].

  4. utils/index.ts (1 error) — BetterAuthError("jwt_config", "jwt plugin not found") — second arg is a string but constructor expects { cause?: unknown }. Silently ignored at runtime. Fix: drop invalid second arg.

Commit 2: Add dist declaration CI check

Adds tsconfig.dist-check.json at the repo root that:

  • Clears customConditions (disables dev-source resolution)
  • Sets composite: false + noEmit: true
  • Includes all downstream package sources, excluding better-auth, core, and electron (top-level packages that can't be dist-checked against themselves due to module augmentation conflicts)

Available locally via pnpm typecheck:dist and runs in CI after the build step.

How to reproduce

pnpm build
pnpm typecheck:dist  # Should pass (0 errors with this PR)

# Without this PR's fixes:
git stash
pnpm typecheck:dist  # Shows 8 oauth-provider errors

Test plan

  • pnpm typecheck (root, dev-source) still passes
  • pnpm lint passes
  • pnpm typecheck:dist — 0 errors (was 8)
  • 216/216 oauth-provider tests pass

🔄 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/8701 **Author:** [@gustavovalverde](https://github.com/gustavovalverde) **Created:** 3/20/2026 **Status:** ✅ Merged **Merged:** 3/20/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `fix/oauth-provider-dist-types` --- ### 📝 Commits (1) - [`554d0b5`](https://github.com/better-auth/better-auth/commit/554d0b50e6148b72c5664dc5f32aca572779666a) fix(oauth-provider): fix dist declaration type errors ### 📊 Changes **4 files changed** (+8 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `packages/oauth-provider/src/client-resource.ts` (+5 -2) 📝 `packages/oauth-provider/src/consent.ts` (+1 -1) 📝 `packages/oauth-provider/src/register.ts` (+1 -1) 📝 `packages/oauth-provider/src/utils/index.ts` (+1 -1) </details> ### 📄 Description ## Summary The `oauth-provider` package has **8 type errors** in its emitted `.d.mts` declarations that are invisible during development but break external consumers. This PR fixes them and adds CI validation to prevent regressions. ### Why these errors are hidden The monorepo uses `customConditions: ["dev-source"]` in `tsconfig.base.json`, which resolves workspace imports to **source `.ts` files** instead of built `dist/` output: ```jsonc // tsconfig.base.json "customConditions": ["dev-source"] ``` Each package exports a `dev-source` condition: ```json "dev-source": "./src/index.ts" ``` So `pnpm typecheck` (root `tsc --build`) resolves all cross-package imports to source — types are always consistent. **But the published dist declarations have real type issues.** | Scenario | What TypeScript sees | Result | |---|---|---| | Root `tsc --build` | Source `.ts` via dev-source | Passes | | Package-level `tsc --noEmit` | Source with dist deps (no build mode) | **8 errors** | | External consumer via npm | Dist `.d.mts` files | **Broken types** | ### Commit 1: Fix the 8 type errors 1. **`client-resource.ts`** (5 errors) — `auth?.options.baseURL` typed as `BaseURLConfig` (includes `DynamicBaseURLConfig`) in dist. **Fix:** narrow to `string | undefined` with a `typeof` check. 2. **`consent.ts`** (1 error) — `ctx.context.postLogin` doesn't exist on dist `AuthContext` (dynamically added at runtime). **Fix:** cast to `Record<string, unknown>`. 3. **`register.ts`** (1 error) — `redirect_uris` typed as `string[] | undefined` in dist, assigned to `string[]`. **Fix:** default to `[]`. 4. **`utils/index.ts`** (1 error) — `BetterAuthError("jwt_config", "jwt plugin not found")` — second arg is a string but constructor expects `{ cause?: unknown }`. Silently ignored at runtime. **Fix:** drop invalid second arg. ### Commit 2: Add dist declaration CI check Adds `tsconfig.dist-check.json` at the repo root that: - Clears `customConditions` (disables `dev-source` resolution) - Sets `composite: false` + `noEmit: true` - Includes all downstream package sources, excluding `better-auth`, `core`, and `electron` (top-level packages that can't be dist-checked against themselves due to module augmentation conflicts) Available locally via `pnpm typecheck:dist` and runs in CI after the build step. ### How to reproduce ```bash pnpm build pnpm typecheck:dist # Should pass (0 errors with this PR) # Without this PR's fixes: git stash pnpm typecheck:dist # Shows 8 oauth-provider errors ``` ## Test plan - [x] `pnpm typecheck` (root, dev-source) still passes - [x] `pnpm lint` passes - [x] `pnpm typecheck:dist` — 0 errors (was 8) - [x] 216/216 oauth-provider tests pass --- <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-04-15 22:42:34 -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#25058