Skip to content

Commit cf3396a

Browse files
chore: include isRequired in Validator
1 parent d90069e commit cf3396a

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ export interface NormalizeEmailOptions {
247247

248248
export interface Validator<T> {
249249
name: ValidationNames
250+
isRequired: boolean
250251
getRules: () => ValidationRule<T>[]
251252
test: (value: T) => boolean
252253
validate: (value: T) => ValidationResult
@@ -359,7 +360,9 @@ export interface ValidationInstance {
359360
password: () => PasswordValidatorType
360361
}
361362

362-
export type ValidationType = StringValidatorType | NumberValidatorType | ArrayValidatorType<string | number | boolean | Date> | BooleanValidatorType | EnumValidatorType<string | number> | DateValidatorType | DatetimeValidatorType | ObjectValidatorType<Record<string, any>> | CustomValidatorType<Record<string, any>> | TimestampValidatorType | UnixValidatorType | PasswordValidatorType
363+
export type ValidationType = {
364+
[K in keyof ValidationInstance]: ReturnType<ValidationInstance[K]>
365+
}[keyof ValidationInstance]
363366

364367
export type Infer<T> = T extends Validator<infer U> ? U : never
365368

src/validators/base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { ValidationError, ValidationErrorMap, ValidationNames, ValidationRe
22

33
export abstract class BaseValidator<T> {
44
protected rules: ValidationRule<T>[] = []
5-
protected isRequired = false
5+
public isRequired = false
66
protected fieldName = 'value'
77
protected isPartOfShape = false
88
public name: ValidationNames = 'base'

0 commit comments

Comments
 (0)