Skip to content

v2 draft#109

Draft
himself65 wants to merge 13 commits intobetter-auth:mainfrom
himself65:v2
Draft

v2 draft#109
himself65 wants to merge 13 commits intobetter-auth:mainfrom
himself65:v2

Conversation

@himself65
Copy link
Member

🚀 Better Call v2: Endpoint Type Optimization & API Refactor

Summary

This PR introduces the core architectural changes for Better Call v2. The primary focus is to significantly improve TypeScript compiler performance, enhance type inference for developers, and prune the public API surface to reduce bundle bloat.

Key Changes

1. Refactor createEndpoint Generic Signature

We are moving away from the monolithic Options object in favor of flattened generics.

  • Problem: The previous Options extends EndpointOptions approach forced the TypeScript compiler to parse a massive, deeply nested object for every endpoint, leading to sluggish IDE performance and slow CI type-checking.
  • Solution: Flattened the signature to allow direct inference of Body, Query, Params, etc.

Before:

function createEndpoint<Path, Options, R>(): StrictEndpoint<Path, ExtractSchema<Options>, R>

After:

function createEndpoint<
  Path extends string,
  Body extends object,
  Query extends object,
  // ...other specific generics
  Res
>(): Endpoint<Path, Body, Query, Res>

2. API Surface Hardening (Export Cleanup)

  • Restricted Wildcard Exports: Removed export type * from '../*.ts'. This was leaking internal utility types and polluting the consumer's namespace.
  • Explicit Exports: All public-facing types and functions are now explicitly exported from the entry point. Internal-only logic has been scoped to its respective module.

3. Dead Code Elimination (DCE)

  • Removed legacy EndpointOptions and StrictEndpoint types that were rendered obsolete by the new generic structure.
  • Pruned unused helper functions discovered during the refactor of the export tree.

Impact

  • DX: Faster IntelliSense and more accurate type inference when calling createEndpoint.
  • Performance: Reduced type-checking time in the compiler.
  • Stability: Clearer boundaries between internal logic and the public API.

Breaking Changes ⚠️

  • The createEndpoint signature has changed. Consumers migrating from v1 will need to update their endpoint definitions to the new flattened generic format.
  • Some internal types previously accessible via wildcard exports are no longer available externally.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 17, 2026

Open in StackBlitz

npm i https://pkg.pr.new/better-auth/better-call@109

commit: 185d8c1

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