Skip to content
Myr

fix(req): fix inferring types in `req.valid()` (#1351)

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

* fix(req): fix inferring types in `req.valid()` * denoify

authored by Yusuke Wada · committed by GitHub · parent dc0696f · Browse files · 3 files+8 added−26 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+8 added−26 removed

  • tests:+2 added−2 removed
  • other:+6 added−24 removed

3 files+8 added−26 removed

modified:deno_dist/request.ts+3 added-12 removed
modified:src/request.test.ts+2 added-2 removed
42 unmodified lines
43 },44 }4546 test('add data - json', () => {47 const req = new HonoRequest(rawRequest)47 const req = new HonoRequest<'/', { json: typeof payload }>(rawRequest)48 req.addValidatedData('json', payload)49 const data = req.valid('json')50 expect(data).toEqual(payload)51 })5253 test('replace data - json', () => {54 const req = new HonoRequest(rawRequest)54 const req = new HonoRequest<'/', { json: typeof payload }>(rawRequest)55 req.addValidatedData('json', payload)56 req.addValidatedData('json', {57 tag: ['sport', 'music'],58 author: {
83 unmodified lines
modified:src/request.ts+3 added-12 removed
153 unmodified lines
154 addValidatedData(target: keyof ValidationTargets, data: {}) {155 this.vData[target] = data156 }157158 valid<159 T extends keyof ValidationTargets = I extends Record<infer R, unknown>160 ? R extends keyof ValidationTargets161 ? R162 : never163 : never164 >(target: T): InputToDataByTarget<I, T>165 valid(): never166 valid(target?: keyof ValidationTargets) {167 if (target) {168 return this.vData[target] as unknown169 }158 valid<T extends keyof I & keyof ValidationTargets>(target: T): InputToDataByTarget<I, T>159 valid(target: keyof ValidationTargets) {160 return this.vData[target] as unknown161 }162163 get url() {164 return this.raw.url
26 unmodified lines