Skip to content
Myr

fix(types): allow symbol keys in Context<any> get and set fallbacks (#5300)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* fix(types): allow symbol keys in Context<any> get and set fallbacks Fixes #5298 Signed-off-by: Liang Xu <lx3133584@users.noreply.github.com> * refactor(types): use PropertyKey for untyped Context get/set fallbacks Signed-off-by: Liang Xu <lx3133584@users.noreply.github.com> * ci: apply automated fixes ---------

authored by Liang Xu · committed by GitHub · parent 499c35e · Browse files · 2 files+11 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Signed-off-by: Liang Xu <lx3133584@users.noreply.github.com>
  • Co-authored-by: Liang Xu <lx3133584@users.noreply.github.com>
  • Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>

Diff stats

2 files+11 added−4 removed

  • tests:+7 added−0 removed
  • other:+4 added−4 removed

2 files+11 added−4 removed

modified:src/context.test.ts+7 added
142 unmodified lines
143 const foo = res.headers.get('X-Foo')144 expect(foo).toBe('Bar, Buzz')145 })146147 it('c.set() and c.get() with symbol key', () => {148 const sym = Symbol('key')149 expect(c.get(sym)).toBe(undefined)150 c.set(sym, 'value')151 expect(c.get(sym)).toBe('value')152 })153154 it('c.set() and c.get()', async () => {155 expect(c.get('foo')).toBe(undefined)156 c.set('foo', 'bar')157 expect(c.get('foo')).toBe('bar')
462 unmodified lines
modified:src/context.ts+4 added-4 removed
549 unmodified lines
550 set: Set<551 IsAny<E> extends true552 ? {553 // eslint-disable-next-line @typescript-eslint/no-explicit-any554 Variables: ContextVariableMap & Record<string, any>554 Variables: ContextVariableMap & Record<PropertyKey, any>555 }556 : E557 > = (key: string, value: unknown) => {557 > = (key: PropertyKey, value: unknown) => {558 this.#var ??= new Map()559 this.#var.set(key, value)560 }561
13 unmodified lines
575 get: Get<576 IsAny<E> extends true577 ? {578 // eslint-disable-next-line @typescript-eslint/no-explicit-any579 Variables: ContextVariableMap & Record<string, any>579 Variables: ContextVariableMap & Record<PropertyKey, any>580 }581 : E582 > = (key: string) => {582 > = (key: PropertyKey) => {583 return this.#var ? this.#var.get(key) : undefined584 }585586 /**
211 unmodified lines