Fix object validator (#2897)
Make sure we check if we have the optional function before calling it ### Change Type - [x] `patch` — Bug fix - [ ] `minor` — New feature - [ ] `major` — Breaking change - [ ] `dependencies` — Changes to package dependencies[^1] - [ ] `documentation` — Changes to the documentation only[^2] - [ ] `tests` — Changes to any test code only[^2] - [ ] `internal` — Any other changes that don't affect the published package[^2] - [ ] I don't know [^1]: publishes a `patch` release, for devDependencies use `internal` [^2]: will not publish a new version
This commit is contained in:
parent
f5f9da4f64
commit
5fd6b4dca7
1 changed files with 7 additions and 2 deletions
|
@ -290,7 +290,7 @@ export class ObjectValidator<Shape extends object> extends Validator<Shape> {
|
|||
|
||||
for (const [key, validator] of Object.entries(config)) {
|
||||
prefixError(key, () => {
|
||||
;(validator as Validator<unknown>).validate(getOwnProperty(object, key))
|
||||
;(validator as Validatable<unknown>).validate(getOwnProperty(object, key))
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -319,7 +319,12 @@ export class ObjectValidator<Shape extends object> extends Validator<Shape> {
|
|||
continue
|
||||
}
|
||||
const checked = prefixError(key, () => {
|
||||
return (validator as Validator<unknown>).validateUsingKnownGoodVersion(prev, next)
|
||||
const validatable = validator as Validatable<unknown>
|
||||
if (validatable.validateUsingKnownGoodVersion) {
|
||||
return validatable.validateUsingKnownGoodVersion(prev, next)
|
||||
} else {
|
||||
return validatable.validate(next)
|
||||
}
|
||||
})
|
||||
if (!Object.is(checked, prev)) {
|
||||
isDifferent = true
|
||||
|
|
Loading…
Reference in a new issue