Skip to content
Myr

fix(types): relax the type of `c.req.param()` (#2613)

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

* fix(types): relax the type of `c.req.param()` * denoify

authored by Yusuke Wada · committed by GitHub · parent a900fbe · Browse files · 3 files+2 added−2 removed
This commit

State

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

Diff stats

3 files+2 added−2 removed

  • tests:+0 added−2 removed
  • other:+2 added−0 removed

3 files+2 added−2 removed

modified:deno_dist/request.ts+1 added
77 unmodified lines
78 param<P2 extends ParamKeys<P> = ParamKeys<P>>(key: P2 extends `${infer _}?` ? never : P2): string79 param<P2 extends RemoveQuestion<ParamKeys<P>> = RemoveQuestion<ParamKeys<P>>>(80 key: P281 ): string | undefined82 param(key: string): string | undefined83 param<P2 extends string = P>(): UnionToIntersection<ParamKeyToRecord<ParamKeys<P2>>>84 param(key?: string): unknown {85 return key ? this.getDecodedParam(key) : this.getAllDecodedParams()86 }
262 unmodified lines
modified:src/hono.test.ts-2 removed
854 unmodified lines
855856 describe('param with undefined', () => {857 const app = new Hono()858 app.get('/foo/:foo', (c) => {859 // eslint-disable-next-line @typescript-eslint/ban-ts-comment860 /* @ts-ignore */859 const bar = c.req.param('bar')860 return c.json({ foo: bar })861 })862 it('param of /foo/foo should return undefined not "undefined"', async () => {
2514 unmodified lines
modified:src/request.ts+1 added
77 unmodified lines
78 param<P2 extends ParamKeys<P> = ParamKeys<P>>(key: P2 extends `${infer _}?` ? never : P2): string79 param<P2 extends RemoveQuestion<ParamKeys<P>> = RemoveQuestion<ParamKeys<P>>>(80 key: P281 ): string | undefined82 param(key: string): string | undefined83 param<P2 extends string = P>(): UnionToIntersection<ParamKeyToRecord<ParamKeys<P2>>>84 param(key?: string): unknown {85 return key ? this.getDecodedParam(key) : this.getAllDecodedParams()86 }
262 unmodified lines