Skip to content

Commit

Permalink
fix(factory): correct types inside of createMiddleware() (#2081)
Browse files Browse the repository at this point in the history
* fix(factory): correct types inside of `createMiddleware()`

* denoify
  • Loading branch information
yusukebe authored Jan 25, 2024
1 parent 4ec3a9b commit b23cf8d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion deno_dist/helper/factory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,5 +270,5 @@ export class Factory<E extends Env = any, P extends string = any> {
export const createFactory = <E extends Env = any, P extends string = any>() => new Factory<E, P>()

export const createMiddleware = <E extends Env = any, P extends string = any, I extends Input = {}>(
middleware: MiddlewareHandler
middleware: MiddlewareHandler<E, P, I>
) => createFactory<E, P>().createMiddleware<I>(middleware)
3 changes: 2 additions & 1 deletion src/helper/factory/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import { createMiddleware, createFactory } from './index'

describe('createMiddleware', () => {
type Env = { Variables: { foo: string } }
const app = new Hono<Env>()
const app = new Hono()

const mw = (message: string) =>
createMiddleware<Env>(async (c, next) => {
expectTypeOf(c.var.foo).toEqualTypeOf<string>()
c.set('foo', 'bar')
await next()
c.header('X-Message', message)
Expand Down
2 changes: 1 addition & 1 deletion src/helper/factory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,5 +270,5 @@ export class Factory<E extends Env = any, P extends string = any> {
export const createFactory = <E extends Env = any, P extends string = any>() => new Factory<E, P>()

export const createMiddleware = <E extends Env = any, P extends string = any, I extends Input = {}>(
middleware: MiddlewareHandler
middleware: MiddlewareHandler<E, P, I>
) => createFactory<E, P>().createMiddleware<I>(middleware)

0 comments on commit b23cf8d

Please sign in to comment.