Skip to content
Myr

fix(types): `param` in `ValidationTargets` supports optional param (#3229)

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

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

State

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

Diff stats

2 files+8 added−3 removed

  • tests:+5 added−0 removed
  • other:+3 added−3 removed

2 files+8 added−3 removed

modified:src/validator/validator.test.ts+5 added
831 unmodified lines
832 const app = new Hono()833834 const route = app.put(835 '/posts/:id',836 validator('param', () => {837 return {838 id: '123',839 }840 }),841 validator('form', () => {842 return {843 title: 'Foo',844 }
334 unmodified lines
modified:src/types.ts+3 added-3 removed
1806 unmodified lines
1807 ? { [K in Path]: {} }1808 : { [K in keyof S as Path]: S[K] }18091810export type Endpoint = {1811 input: Partial<ValidationTargets>1811 input: any1812 output: any1813 outputFormat: ResponseFormat1814 status: StatusCode1815}
113 unmodified lines
19291930export type FormValue = string | Blob1931export type ParsedFormValue = string | File19321933export type ValidationTargets<T extends FormValue = ParsedFormValue> = {1933export type ValidationTargets<T extends FormValue = ParsedFormValue, P extends string = string> = {1934 json: any1935 form: Record<string, T | T[]>1936 query: Record<string, string | string[]>1937 param: Record<string, string> | Record<string, string | undefined>1937 param: Record<P, P extends `${infer _}?` ? string | undefined : string>1938 header: Record<string, string>1939 cookie: Record<string, string>1940}1941
68 unmodified lines