Skip to content

Commit 1084b5f

Browse files
committed
🔧 fix: type
1 parent 01d03b5 commit 1084b5f

File tree

2 files changed

+41
-27
lines changed

2 files changed

+41
-27
lines changed

src/index.ts

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ import type {
162162
EmptyRouteSchema,
163163
UnknownRouteSchema,
164164
MaybeFunction,
165-
InlineHandlerNonMacro
165+
InlineHandlerNonMacro,
166+
Router
166167
} from './types'
167168

168169
export type AnyElysia = Elysia<any, any, any, any, any, any, any>
@@ -201,7 +202,7 @@ export default class Elysia<
201202
parser: {}
202203
response: {}
203204
},
204-
const out Routes extends RouteBase = {},
205+
const in out Routes extends RouteBase = {},
205206
// ? scoped
206207
const in out Ephemeral extends EphemeralType = {
207208
derive: {}
@@ -222,7 +223,7 @@ export default class Elysia<
222223
config: ElysiaConfig<BasePath>
223224

224225
server: Server | null = null
225-
private dependencies: { [key in string]: Checksum[] } = {}
226+
private dependencies: { [key: string]: Checksum[] } = {}
226227

227228
'~Prefix' = '' as BasePath
228229
'~Singleton' = null as unknown as Singleton
@@ -295,12 +296,7 @@ export default class Elysia<
295296
}
296297

297298
router = {
298-
'~http': undefined as
299-
| Memoirist<{
300-
compile: Function
301-
handler?: ComposedHandler
302-
}>
303-
| undefined,
299+
'~http': undefined,
304300
get http() {
305301
if (!this['~http'])
306302
this['~http'] = new Memoirist({
@@ -310,7 +306,7 @@ export default class Elysia<
310306

311307
return this['~http']
312308
},
313-
'~dynamic': undefined as Memoirist<DynamicHandler> | undefined,
309+
'~dynamic': undefined,
314310
// Use in non-AOT mode
315311
get dynamic() {
316312
if (!this['~dynamic'])
@@ -321,15 +317,11 @@ export default class Elysia<
321317
return this['~dynamic']
322318
},
323319
// Static Router
324-
static: {} as { [path in string]: { [method in string]: number } },
320+
static: {},
325321
// Native Static Response
326-
response: {} as {
327-
[path: string]:
328-
| MaybePromise<Response | undefined>
329-
| { [method: string]: MaybePromise<Response | undefined> }
330-
},
331-
history: [] as InternalRoute[]
332-
}
322+
response: {},
323+
history: []
324+
} as Router
333325

334326
protected routeTree: Record<string, number> = {}
335327

@@ -365,7 +357,7 @@ export default class Elysia<
365357
return null
366358
}
367359

368-
'~parser': { [K in string]: BodyHandler<any, any> } = {}
360+
'~parser': { [K: string]: BodyHandler<any, any> } = {}
369361

370362
private _promisedModules: PromiseGroup | undefined
371363
private get promisedModules() {
@@ -8121,11 +8113,7 @@ export type {
81218113
} from './type-system/types'
81228114

81238115
export { serializeCookie, Cookie, type CookieOptions } from './cookies'
8124-
export type {
8125-
Context,
8126-
PreContext,
8127-
ErrorContext
8128-
} from './context'
8116+
export type { Context, PreContext, ErrorContext } from './context'
81298117
export {
81308118
ELYSIA_TRACE,
81318119
type TraceEvent,

src/types.ts

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ import type { WebSocketHandler } from './ws/bun'
3737
import type { Instruction as ExactMirrorInstruction } from 'exact-mirror'
3838
import { BunHTMLBundlelike } from './universal/types'
3939
import { Sucrose } from './sucrose'
40+
import type Memoirist from 'memoirist'
41+
import type { DynamicHandler } from './dynamic-handle'
4042

4143
export type IsNever<T> = [T] extends [never] ? true : false
4244

@@ -76,7 +78,7 @@ export type StandardSchemaV1LikeValidate = <T>(
7678
export type AnySchema = TSchema | StandardSchemaV1Like
7779
export type FastAnySchema = TAnySchema | FastStandardSchemaV1Like
7880

79-
export interface ElysiaConfig<Prefix extends string | undefined> {
81+
export interface ElysiaConfig<in out Prefix extends string | undefined> {
8082
/**
8183
* @default BunAdapter
8284
* @since 1.1.11
@@ -1753,7 +1755,7 @@ export type LocalHook<
17531755
Singleton extends SingletonBase,
17541756
Errors extends { [key in string]: Error },
17551757
Parser extends keyof any = ''
1756-
> = (Input extends any ? Input : Prettify<Input>) & {
1758+
> = {
17571759
detail?: DocumentDecoration
17581760
/**
17591761
* Short for 'Content-Type'
@@ -1808,7 +1810,7 @@ export type LocalHook<
18081810
ErrorHandler<Errors, Schema, Singleton & { resolve: Schema['resolve'] }>
18091811
>
18101812
tags?: DocumentDecoration['tags']
1811-
}
1813+
} & (Input extends any ? Input : Prettify<Input>)
18121814

18131815
export type GuardLocalHook<
18141816
Input extends BaseMacro | undefined,
@@ -2630,3 +2632,27 @@ export type CreateEdenResponse<
26302632
headers: Prettify<Schema['headers'] & MacroContext['headers']>
26312633
response: Prettify<Res>
26322634
}
2635+
2636+
export interface Router {
2637+
'~http':
2638+
| Memoirist<{
2639+
compile: Function
2640+
handler?: ComposedHandler
2641+
}>
2642+
| undefined
2643+
get http(): Memoirist<{
2644+
compile: Function
2645+
handler?: ComposedHandler
2646+
}>
2647+
'~dynamic': Memoirist<DynamicHandler> | undefined
2648+
get dynamic(): Memoirist<DynamicHandler>
2649+
// Static Router
2650+
static: { [path: string]: { [method: string]: number } }
2651+
// Native Static Response
2652+
response: {
2653+
[path: string]:
2654+
| MaybePromise<Response | undefined>
2655+
| { [method: string]: MaybePromise<Response | undefined> }
2656+
}
2657+
history: InternalRoute[]
2658+
}

0 commit comments

Comments
 (0)