Closed lennykey closed 5 months ago
On a similar note to this, is it possible to somehow infer that a nullable property is non-null if declared as required
in the validation spec?
data class UserProfile(
val fullName: String,
val age: Int?
)
val validateUser = Validation<UserProfile> {
UserProfile::fullName {
minLength(2)
maxLength(100)
}
UserProfile::age required {
minimum(0)
maximum(150)
}
}
val user = UserProfile("username", 1)
val validationResult = validateUser.validate(user)
when (validationResult) {
is Valid -> {
// validationResult.value.age is inferred to type "Int" instead of "Int?"
}
}
Duplicate of #29
Example:
if a firstName was passed to a Person and this firstName is present then the user should also enter a familyName to pass the validation if the firstName was not passed (null) then the validation for the familyName should not be active Something like this should be possible: