diff --git a/src/context.ts b/src/context.ts index b1e826036..a5fb326a1 100644 --- a/src/context.ts +++ b/src/context.ts @@ -69,8 +69,8 @@ export type Layout> = (props: T) => any * @template E - Environment type. */ interface Get { - (key: Key): ContextVariableMap[Key] (key: Key): E['Variables'][Key] + (key: Key): ContextVariableMap[Key] } /** @@ -79,8 +79,8 @@ interface Get { * @template E - Environment type. */ interface Set { - (key: Key, value: ContextVariableMap[Key]): void (key: Key, value: E['Variables'][Key]): void + (key: Key, value: ContextVariableMap[Key]): void } /** diff --git a/src/types.test.ts b/src/types.test.ts index 02e621fb2..9b9a10edb 100644 --- a/src/types.test.ts +++ b/src/types.test.ts @@ -1638,8 +1638,8 @@ declare module './context' { } } -describe('c.var with ContextVariableMap - test only types', () => { - it('Should no throw a type error', () => { +describe('ContextVariableMap type tests', () => { + it('Should not throw type errors with c.var', () => { new Hono().get((c) => { expectTypeOf(c.get('payload')).toEqualTypeOf() return c.json(0) @@ -1649,6 +1649,22 @@ describe('c.var with ContextVariableMap - test only types', () => { return c.json(0) }) }) + + it('Should override ContextVariableMap with env variables', () => { + const middleware = createMiddleware<{ + Variables: { + payload: number + } + }>(async (c, next) => { + c.set('payload', 123) + await next() + }) + + new Hono().get(middleware, (c) => { + expectTypeOf(c.get('payload')).toEqualTypeOf() + return c.json(0) + }) + }) }) /**