Skip to content

Commit

Permalink
📘 refactor: remove inline resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
SaltyAom committed Nov 23, 2024
1 parent fdaecf4 commit a36c1aa
Show file tree
Hide file tree
Showing 4 changed files with 243 additions and 223 deletions.
38 changes: 28 additions & 10 deletions example/a.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
import { Elysia, t } from '../src'

new Elysia()
.macro({
custom: (_: boolean) => ({
resolve: () => ({
a: 'a' as const
const app = new Elysia().get(
'/',
() => {
return {
duration: 200
}
},
{
response: {
200: t.Object({
duration: t.Number()
}),
400: t.Object({
stuff: t.Number()
})
})
})
.get('/', ({ a }) => '', {
custom: true
})
},
afterResponse({ response }) {
// expectTypeOf<typeof response>().toEqualTypeOf<
// | {
// duration: number
// }
// | {
// stuff: number
// }
// >()
// return undefined as any
}
}
)
8 changes: 4 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ export type MacroToContext<
MacroFn extends BaseMacroFn = {},
SelectedMacro extends MetadataBase['macro'] = {}
> = {} extends SelectedMacro
? { c: SelectedMacro }
? {}
: {
[key in keyof SelectedMacro as MacroFn[key] extends (
...v: any[]
Expand All @@ -646,8 +646,8 @@ export type MacroToContext<
} extends infer A extends Record<RecordKey, unknown>
? IsNever<A[keyof A]> extends false
? A[keyof A]
: { b: 'b' }
: { a: 'a' }
: {}
: {}

export type InlineHandler<
Route extends RouteSchema = {},
Expand Down Expand Up @@ -843,7 +843,7 @@ export type AfterResponseHandler<
: Route['response'][keyof Route['response']]
}
>
) => MaybePromise<void>
) => MaybePromise<unknown>

export type GracefulHandler<in Instance extends AnyElysia> = (
data: Instance
Expand Down
18 changes: 10 additions & 8 deletions test/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1915,14 +1915,16 @@ type a = keyof {}
})
},
afterResponse({ response }) {
expectTypeOf<typeof response>().toEqualTypeOf<
| {
duration: number
}
| {
stuff: number
}
>()
// expectTypeOf<typeof response>().toEqualTypeOf<
// | {
// duration: number
// }
// | {
// stuff: number
// }
// >()

// return undefined as any
}
}
)
Expand Down
Loading

0 comments on commit a36c1aa

Please sign in to comment.