Skip to content

Commit

Permalink
fix!(types): Fix context type when chaining routes with middlewares (#…
Browse files Browse the repository at this point in the history
…2046)

* fix(types): Fix handler return types not to leak Context types

* fix specs

* denoify

* fix specs

* yarm format:fix && yarn denoify

* Add tests
  • Loading branch information
agatan authored Jan 23, 2024
1 parent 66e768e commit 64a24d7
Show file tree
Hide file tree
Showing 3 changed files with 404 additions and 244 deletions.
56 changes: 10 additions & 46 deletions deno_dist/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,11 +394,7 @@ export interface HandlerInterface<
>(
path: P,
handler: H<E2, MergedPath, I, R>
): Hono<
IntersectNonAnyTypes<[E, E2]>,
S & ToSchema<M, MergePath<BasePath, P>, I['in'], MergeTypedResponseData<R>>,
BasePath
>
): Hono<E, S & ToSchema<M, MergePath<BasePath, P>, I['in'], MergeTypedResponseData<R>>, BasePath>

// app.get(path, handler x2)
<
Expand All @@ -412,11 +408,7 @@ export interface HandlerInterface<
>(
path: P,
...handlers: [H<E2, MergedPath, I>, H<E3, MergedPath, I2, R>]
): Hono<
IntersectNonAnyTypes<[E, E2, E3]>,
S & ToSchema<M, MergePath<BasePath, P>, I2['in'], MergeTypedResponseData<R>>,
BasePath
>
): Hono<E, S & ToSchema<M, MergePath<BasePath, P>, I2['in'], MergeTypedResponseData<R>>, BasePath>

// app.get(path, handler x3)
<
Expand All @@ -432,11 +424,7 @@ export interface HandlerInterface<
>(
path: P,
...handlers: [H<E2, MergedPath, I>, H<E3, MergedPath, I2>, H<E4, MergedPath, I3, R>]
): Hono<
IntersectNonAnyTypes<[E, E2, E3, E4]>,
S & ToSchema<M, MergePath<BasePath, P>, I3['in'], MergeTypedResponseData<R>>,
BasePath
>
): Hono<E, S & ToSchema<M, MergePath<BasePath, P>, I3['in'], MergeTypedResponseData<R>>, BasePath>

// app.get(path, handler x4)
<
Expand All @@ -459,11 +447,7 @@ export interface HandlerInterface<
H<E4, MergedPath, I3>,
H<E5, MergedPath, I4, R>
]
): Hono<
IntersectNonAnyTypes<[E, E2, E3, E4, E5]>,
S & ToSchema<M, MergePath<BasePath, P>, I4['in'], MergeTypedResponseData<R>>,
BasePath
>
): Hono<E, S & ToSchema<M, MergePath<BasePath, P>, I4['in'], MergeTypedResponseData<R>>, BasePath>

// app.get(path, handler x5)
<
Expand All @@ -489,11 +473,7 @@ export interface HandlerInterface<
H<E5, MergedPath, I4>,
H<E6, MergedPath, I5, R>
]
): Hono<
IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6]>,
S & ToSchema<M, MergePath<BasePath, P>, I5['in'], MergeTypedResponseData<R>>,
BasePath
>
): Hono<E, S & ToSchema<M, MergePath<BasePath, P>, I5['in'], MergeTypedResponseData<R>>, BasePath>

// app.get(path, handler x6)
<
Expand Down Expand Up @@ -522,11 +502,7 @@ export interface HandlerInterface<
H<E6, MergedPath, I5>,
H<E7, MergedPath, I6, R>
]
): Hono<
IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7]>,
S & ToSchema<M, MergePath<BasePath, P>, I6['in'], MergeTypedResponseData<R>>,
BasePath
>
): Hono<E, S & ToSchema<M, MergePath<BasePath, P>, I6['in'], MergeTypedResponseData<R>>, BasePath>

// app.get(path, handler x7)
<
Expand Down Expand Up @@ -558,11 +534,7 @@ export interface HandlerInterface<
H<E7, MergedPath, I6>,
H<E8, MergedPath, I7, R>
]
): Hono<
IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8]>,
S & ToSchema<M, MergePath<BasePath, P>, I7['in'], MergeTypedResponseData<R>>,
BasePath
>
): Hono<E, S & ToSchema<M, MergePath<BasePath, P>, I7['in'], MergeTypedResponseData<R>>, BasePath>

// app.get(path, handler x8)
<
Expand Down Expand Up @@ -597,11 +569,7 @@ export interface HandlerInterface<
H<E8, MergedPath, I7>,
H<E9, MergedPath, I8, R>
]
): Hono<
IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9]>,
S & ToSchema<M, MergePath<BasePath, P>, I8['in'], MergeTypedResponseData<R>>,
BasePath
>
): Hono<E, S & ToSchema<M, MergePath<BasePath, P>, I8['in'], MergeTypedResponseData<R>>, BasePath>

// app.get(path, handler x9)
<
Expand Down Expand Up @@ -639,11 +607,7 @@ export interface HandlerInterface<
H<E9, MergedPath, I8>,
H<E10, MergedPath, I9, R>
]
): Hono<
IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10]>,
S & ToSchema<M, MergePath<BasePath, P>, I9['in'], MergeTypedResponseData<R>>,
BasePath
>
): Hono<E, S & ToSchema<M, MergePath<BasePath, P>, I9['in'], MergeTypedResponseData<R>>, BasePath>

// app.get(path, handler x10)
<
Expand Down Expand Up @@ -685,7 +649,7 @@ export interface HandlerInterface<
H<E11, MergedPath, I10, R>
]
): Hono<
IntersectNonAnyTypes<[E, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11]>,
E,
S & ToSchema<M, MergePath<BasePath, P>, I10['in'], MergeTypedResponseData<R>>,
BasePath
>
Expand Down
Loading

0 comments on commit 64a24d7

Please sign in to comment.