diff --git a/src/index.ts b/src/index.ts index d184b159..615e8550 100644 --- a/src/index.ts +++ b/src/index.ts @@ -125,7 +125,8 @@ import type { HigherOrderFunction, ResolvePath, JoinPath, - ValidatorLayer + ValidatorLayer, + RouteConfig } from './types' export type AnyElysia = Elysia @@ -437,7 +438,7 @@ export default class Elysia< path: string, handle: Handler | any, localHook?: LocalHook, - { allowMeta = false, skipPrefix = false } = { + { allowMeta = false, skipPrefix = false }: RouteConfig = { allowMeta: false as boolean | undefined, skipPrefix: false as boolean | undefined } @@ -4522,11 +4523,8 @@ export default class Elysia< Definitions['error'], Metadata['macro'], JoinPath - > & { - config: { - allowMeta?: boolean - } - } + > & + Partial<{ config: RouteConfig }> ): Elysia< BasePath, Scoped, diff --git a/src/types.ts b/src/types.ts index 2c44803e..5fe3118a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -301,6 +301,11 @@ export interface DefinitionBase { export type RouteBase = Record +export interface RouteConfig { + allowMeta?: boolean | undefined + skipPrefix?: boolean | undefined +} + export interface MetadataBase { schema: RouteSchema macro: BaseMacro @@ -640,7 +645,7 @@ export type OptionalHandler< Path extends string = '' > = Handler extends ( - context: infer Context + context: Context ) => infer Returned ? (context: Context) => Returned | MaybePromise : never @@ -656,7 +661,7 @@ export type AfterHandler< Path extends string = '' > = Handler extends ( - context: infer Context + context: Context ) => infer Returned ? ( context: Prettify< diff --git a/test/types/index.ts b/test/types/index.ts index 9146b24f..93c1f91d 100644 --- a/test/types/index.ts +++ b/test/types/index.ts @@ -724,6 +724,7 @@ app.group( '/:a', { beforeHandle({ params, params: { a } }) { + // @ts-expect-error expectTypeOf().toEqualTypeOf<{ a: string }>() @@ -754,6 +755,7 @@ app.group( '/:c', { beforeHandle({ params, params: { a, c } }) { + // @ts-expect-error expectTypeOf().toEqualTypeOf<{ a: string c: string @@ -785,6 +787,7 @@ app.group( user: t.String() }), beforeHandle: ({ body }) => { + // @ts-expect-error expectTypeOf().toEqualTypeOf<{ username: string }>() @@ -795,10 +798,12 @@ app.group( '/:c', { beforeHandle({ body, query }) { + // @ts-expect-error expectTypeOf().toEqualTypeOf<{ password: string }>() + // @ts-expect-error expectTypeOf().toEqualTypeOf<{ user: string }>() @@ -992,6 +997,7 @@ app.group( id: t.Numeric() }), beforeHandle({ params }) { + // @ts-expect-error expectTypeOf().toEqualTypeOf<{ id: number }>() @@ -1072,11 +1078,12 @@ app.group( }) } -const a = app.resolve(({ headers }) => { - return { - authorization: headers.authorization as string - } -}) +const a = app + .resolve(({ headers }) => { + return { + authorization: headers.authorization as string + } + }) // .get('/', ({ authorization }) => { // // ? infers derive type // expectTypeOf().toBeString() @@ -1106,6 +1113,7 @@ const a = app.resolve(({ headers }) => { .onBeforeHandle((context) => { expectTypeOf< 'b' extends keyof typeof context ? true : false + // @ts-expect-error >().toEqualTypeOf() })