Skip to content

Commit

Permalink
🔧 fix: type error
Browse files Browse the repository at this point in the history
  • Loading branch information
SaltyAom committed Oct 4, 2024
1 parent 80ef653 commit 37ba784
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type { CookieOptions } from './cookies'
import type { TraceHandler } from './trace'
import type { Context, ErrorContext, PreContext } from './context'
import type {
ELYSIA_RESPONSE,
ElysiaCustomStatusResponse,
InternalServerError,
InvalidCookieSignature,
NotFoundError,
Expand Down Expand Up @@ -614,13 +614,11 @@ export type InlineHandler<
: string | number | boolean | Object)
| Route['response'][keyof Route['response']]
| {
[Status in keyof Route['response']]: {
_type: Record<
Status,
Route['response'][Status]
>
[ELYSIA_RESPONSE]: Status
}
[Status in keyof Route['response']]: ElysiaCustomStatusResponse<
// @ts-ignore Status is always a number
Status,
Route['response'][Status]
>
}[keyof Route['response']]
>)
| ({} extends Route['response']
Expand All @@ -631,10 +629,11 @@ export type InlineHandler<
: string | number | boolean | Object)
| Route['response'][keyof Route['response']]
| {
[Status in keyof Route['response']]: {
_type: Record<Status, Route['response'][Status]>
[ELYSIA_RESPONSE]: Status
}
[Status in keyof Route['response']]: ElysiaCustomStatusResponse<
// @ts-ignore Status is always a number
Status,
Route['response'][Status]
>
}[keyof Route['response']])

export type OptionalHandler<
Expand Down Expand Up @@ -1199,15 +1198,17 @@ export type ComposeElysiaResponse<Response, Handle> = Handle extends (
type _ComposeElysiaResponse<Response, Handle> = Prettify<
{} extends Response
? {
200: Exclude<Handle, { [ELYSIA_RESPONSE]: any }>
200: Exclude<Handle, ElysiaCustomStatusResponse<any, any, any>>
} & {
[ErrorResponse in Extract<
Handle,
{ response: any }
> as ErrorResponse extends {
[ELYSIA_RESPONSE]: infer Status extends number
}
? Status
ElysiaCustomStatusResponse<any, any, any>
> as ErrorResponse extends ElysiaCustomStatusResponse<
any,
any,
any
>
? ErrorResponse['code']
: never]: ErrorResponse['response']
}
: Response
Expand Down Expand Up @@ -1285,7 +1286,7 @@ export type LifeCycleType = 'global' | 'local' | 'scoped'
// Exclude return error()
export type ExcludeElysiaResponse<T> = Exclude<
undefined extends Awaited<T> ? Partial<Awaited<T>> : Awaited<T>,
{ [ELYSIA_RESPONSE]: any }
ElysiaCustomStatusResponse<any, any, any>
>

export type InferContext<
Expand Down

0 comments on commit 37ba784

Please sign in to comment.