Skip to content

Commit

Permalink
fix validators with args type-check error in ts 5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
yoni-rapoport committed May 22, 2024
1 parent 9127399 commit 551c2de
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion misc/public-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2522,7 +2522,7 @@ export declare class Validators {
export type ValidatorWithArgs<valueType, argsType> = (
args: argsType,
message?: ValidationMessage<valueType, argsType>,
) => FieldValidator<any, valueType>
) => FieldValidator<unknown, valueType>
export interface ValueConverter<valueType> {
/**
* Converts a value from a JSON DTO to the valueType. This method is typically used when receiving data
Expand Down
6 changes: 4 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion projects/core/src/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export type ValidationMessage<valueType, argsType> =
export type ValidatorWithArgs<valueType, argsType> = (
args: argsType,
message?: ValidationMessage<valueType, argsType>,
) => FieldValidator<any, valueType>
) => FieldValidator<unknown, valueType>

export function createValidatorWithArgs<valueType, argsType>(
validate: (
Expand Down
6 changes: 6 additions & 0 deletions projects/tests/strict/test-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ export class Task {
validate: Validators.unique('Has to be Unique'),
})
nom3?: string

@Fields.string<Task>({
allowNull: true,
validate: Validators.minLength(3),
})
nom4?: string
}

function dateOnly<entityType = any>(o?: FieldOptions<entityType, Date>) {
Expand Down

0 comments on commit 551c2de

Please sign in to comment.