diff --git a/deno_dist/context.ts b/deno_dist/context.ts index 3e3d87ec..9769e710 100644 --- a/deno_dist/context.ts +++ b/deno_dist/context.ts @@ -225,8 +225,8 @@ export class Context< } // c.var.propName is a read-only - get var(): Readonly { - return { ...this._var } + get var(): Readonly { + return { ...this._var } as never } newResponse: NewResponse = ( diff --git a/src/context.ts b/src/context.ts index 4ca04362..14c66b4e 100644 --- a/src/context.ts +++ b/src/context.ts @@ -225,8 +225,8 @@ export class Context< } // c.var.propName is a read-only - get var(): Readonly { - return { ...this._var } + get var(): Readonly { + return { ...this._var } as never } newResponse: NewResponse = ( diff --git a/src/types.test.ts b/src/types.test.ts index 396c65c5..378ac63e 100644 --- a/src/types.test.ts +++ b/src/types.test.ts @@ -734,3 +734,26 @@ describe('c.var with chaining - test only types', () => { }) }) }) + +/** + * + * Declaring a ContextVariableMap for testing. + */ +declare module './context' { + interface ContextVariableMap { + payload: string + } +} + +describe('c.var with ContextVariableMap - test only types', () => { + it('Should no throw a type error', () => { + new Hono().get((c) => { + expectTypeOf(c.get('payload')).toEqualTypeOf() + return c.json(0) + }) + new Hono().get((c) => { + expectTypeOf(c.var.payload).toEqualTypeOf() + return c.json(0) + }) + }) +})