Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Relaxing the type. It's not necessary to be strict.

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