Skip to content

Commit

Permalink
fix(types): param in ValidationTargets supports optional param (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
yusukebe authored Aug 6, 2024
1 parent b3b1e8a commit d58b98a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1808,7 +1808,7 @@ type ChangePathOfSchema<S extends Schema, Path extends string> = keyof S extends
: { [K in keyof S as Path]: S[K] }

export type Endpoint = {
input: Partial<ValidationTargets>
input: any
output: any
outputFormat: ResponseFormat
status: StatusCode
Expand Down Expand Up @@ -1930,11 +1930,11 @@ type MergeTypedResponse<T> = T extends Promise<infer T2>
export type FormValue = string | Blob
export type ParsedFormValue = string | File

export type ValidationTargets<T extends FormValue = ParsedFormValue> = {
export type ValidationTargets<T extends FormValue = ParsedFormValue, P extends string = string> = {
json: any
form: Record<string, T | T[]>
query: Record<string, string | string[]>
param: Record<string, string> | Record<string, string | undefined>
param: Record<P, P extends `${infer _}?` ? string | undefined : string>
header: Record<string, string>
cookie: Record<string, string>
}
Expand Down
5 changes: 5 additions & 0 deletions src/validator/validator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,11 @@ it('With path parameters', () => {

const route = app.put(
'/posts/:id',
validator('param', () => {
return {
id: '123',
}
}),
validator('form', () => {
return {
title: 'Foo',
Expand Down

0 comments on commit d58b98a

Please sign in to comment.