mirror of
https://github.com/honojs/hono.git
synced 2024-12-01 11:51:01 +01:00
fix(context): implement ContextVariableMap
for c.var
(#1682)
* fix(context): implement `ContextVariableMap` for `c.var` * denoify
This commit is contained in:
parent
47942ffc68
commit
db3387353f
@ -225,8 +225,8 @@ export class Context<
|
||||
}
|
||||
|
||||
// c.var.propName is a read-only
|
||||
get var(): Readonly<E['Variables']> {
|
||||
return { ...this._var }
|
||||
get var(): Readonly<E['Variables'] & ContextVariableMap> {
|
||||
return { ...this._var } as never
|
||||
}
|
||||
|
||||
newResponse: NewResponse = (
|
||||
|
@ -225,8 +225,8 @@ export class Context<
|
||||
}
|
||||
|
||||
// c.var.propName is a read-only
|
||||
get var(): Readonly<E['Variables']> {
|
||||
return { ...this._var }
|
||||
get var(): Readonly<E['Variables'] & ContextVariableMap> {
|
||||
return { ...this._var } as never
|
||||
}
|
||||
|
||||
newResponse: NewResponse = (
|
||||
|
@ -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<string>()
|
||||
return c.json(0)
|
||||
})
|
||||
new Hono().get((c) => {
|
||||
expectTypeOf(c.var.payload).toEqualTypeOf<string>()
|
||||
return c.json(0)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user