Skip to content

[Feature] Export RouteInput type#1760

Open
thadeucity wants to merge 5 commits intoelysiajs:mainfrom
thadeucity:feat/routes-input
Open

[Feature] Export RouteInput type#1760
thadeucity wants to merge 5 commits intoelysiajs:mainfrom
thadeucity:feat/routes-input

Conversation

@thadeucity
Copy link

@thadeucity thadeucity commented Feb 26, 2026

Export RouteInput type to fix a bug in elysia/eden

Today Elysia/eden is unable to infer the route input type, this pull request aims to fix this issue by exporting its input types.

import { Elysia } from "elysia";
import { z } from 'zod'

const app = new Elysia()
  .post(
    "/sum", 
    ({body}) => `Sum of ${body.foo} + 2 = ${body.foo + 2}`, 
    { 
      body: z.object({ foo: z.string().transform((numericVal) => parseInt(numericVal)) })
    }
  ).listen(3000);

type Input = typeof app['~RoutesInput']['sum']['post']['body']
/*
{
    foo: string;
}
*/


type Output = typeof app['~Routes']['sum']['post']['body']
/*
{
    foo: number;
}
*/

Summary by CodeRabbit

  • New Features

    • Expanded public type surface with richer route-input and schema input/output typings for higher-fidelity type inference across routes, bodies, headers, query, params and responses.
    • Route-building signatures now expose the enhanced input typing for more accurate developer tooling and autocompletion.
  • Tests

    • Added comprehensive type-level tests validating inference for transformed and nested schemas.
  • Notes

    • Purely type-level changes — no runtime behavior changes.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 26, 2026

Walkthrough

Type-level routing infrastructure expanded: new utilities UnwrapRouteInput, InferRouteInput, StripRouteInput added; Elysia class gains a generic RoutesInput and public member ~RoutesInput; comprehensive TypeBox schema unwrapping/transform metadata utilities introduced. Changes are type-level only.

Changes

Cohort / File(s) Summary
Core Elysia Public API
src/index.ts
Adds generic parameter RoutesInput to Elysia, introduces public member ~RoutesInput, changes ~Routes to StripRouteInput<Routes>, and updates route-building method signatures to propagate UnwrapRouteInput and related input types.
Type System / Schema Utilities
src/types.ts
Introduces TypeBox wrapper handling and transform metadata (UnwrapWrappers, TransformMetadata, TypeBoxTransformInput, IsOptionalSchema, TypeBoxStaticEncode), adds schema resolution utilities (UnwrapSchema*, UnwrapBodySchema*, UnwrapRoute*), route-input machinery (routeInputSymbol, StripRouteInput, InferRouteInput, InferElysiaRoutesInput), and updates merge/create types to propagate RoutesInput.
Type Tests
test/types/routes-input.ts
Adds comprehensive TypeScript tests verifying route input inference and unwrapping across body, query, headers, params, and responses using transformed/coerced schemas and nested structures; purely type-level tests.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐇 I nibble types and hop in delight,
I unwrap inputs through day and night,
Schemas transform — I twitch my nose,
Routes revealed where inference grows,
Hooray! a rabbit's tiny type-joys rite.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Export RouteInput type' clearly and concisely describes the main change—exposing RouteInput types to the public API to enable type inference improvements in elysia/eden.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/index.ts`:
- Around line 230-231: The current type alias RoutesInput (declared as RouteBase
& InferRouteInput<Routes>) is being lost during composition because downstream
signatures derive from StripRouteInput<Routes> (i.e., NewElysia['~Routes'])
which strips input metadata; update the composition return types to explicitly
thread and merge RoutesInput (e.g., merge with NewElysia['~RoutesInput'])
instead of re-deriving only from StripRouteInput<Routes>, and adjust affected
composition helpers (use, group, guard and any functions producing NewElysia) so
they carry and combine NewElysia['~RoutesInput'] alongside NewElysia['~Routes']
to preserve route-input metadata across merges.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bbaf6b7 and cdbdbaa.

📒 Files selected for processing (3)
  • src/index.ts
  • src/types.ts
  • test/types/routes-input.ts

@thadeucity
Copy link
Author

Solves #1748

@thadeucity
Copy link
Author

Added Code Rabbit suggestion

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/index.ts (1)

5798-5803: Consider extracting a helper alias for repeated route-input unwrapping.

The repeated UnwrapRouteInput<Input, Definitions['typebox'], JoinPath<BasePath, Path>> pattern across handlers is correct but verbose; a local type alias would reduce duplication and drift risk.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/index.ts` around lines 5798 - 5803, Create a local type alias to reduce
repeated verbosity of UnwrapRouteInput by declaring something like
RouteInput<Input, Path> = UnwrapRouteInput<Input, Definitions['typebox'],
JoinPath<BasePath, Path>> near the handlers; then replace occurrences of
UnwrapRouteInput<Input, Definitions['typebox'], JoinPath<BasePath, Path>> with
the new alias (referencing the existing symbols UnwrapRouteInput,
Definitions['typebox'], JoinPath, BasePath, Path) so all handlers use the
shorter RouteInput alias and avoid duplication.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/index.ts`:
- Around line 5798-5803: Create a local type alias to reduce repeated verbosity
of UnwrapRouteInput by declaring something like RouteInput<Input, Path> =
UnwrapRouteInput<Input, Definitions['typebox'], JoinPath<BasePath, Path>> near
the handlers; then replace occurrences of UnwrapRouteInput<Input,
Definitions['typebox'], JoinPath<BasePath, Path>> with the new alias
(referencing the existing symbols UnwrapRouteInput, Definitions['typebox'],
JoinPath, BasePath, Path) so all handlers use the shorter RouteInput alias and
avoid duplication.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cdbdbaa and 4ef7494.

📒 Files selected for processing (1)
  • src/index.ts

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