feat: add createElysia factory helper to preserve prefix literal types#1726
feat: add createElysia factory helper to preserve prefix literal types#1726shisashi wants to merge 1 commit intoelysiajs:mainfrom
createElysia factory helper to preserve prefix literal types#1726Conversation
When sub-apps are created via a non-generic factory function (e.g. `const create = (opts?) => new Elysia(opts)`), the `const` generic inference for `BasePath` is lost — the prefix widens to `string`, producing index signatures in `CreateEden` that cause response types to intersect when multiple plugins are composed via `.use()`. `createElysia` is a thin generic wrapper around `new Elysia()` that preserves the literal prefix type, giving users a drop-in replacement for the common factory pattern. Closes elysiajs#1725 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
WalkthroughA new type-safe factory function Changes
Possibly related issues
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 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. Comment |
Summary
createElysia<const P>()— a type-safe factory function that preserves the literal prefix type viaconstgeneric inference.group()+.use()Closes #1725
Motivation
When multiple Elysia sub-apps are created via a plain (non-generic) factory function and composed under
.group()via.use(), theBasePathgeneric widens tostring. This causesCreateEdento produce index signatures ({ [x: string]: ... }) instead of literal keys, and TypeScript's&intersection merges all response types together.createElysiais a thin wrapper that preserves the literal type:See issue #1725 for the full root cause analysis.
Test plan
tsc --project tsconfig.test.jsonpasses (including the new type test)import { createElysia } from 'elysia'🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Tests