hapijs / hapijs/joi

ValidationResult type inconsistent with API

Open
#2,510 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
21.2k
Forks
1.5k
Avg merge
4h 57m
Merged PRs (30d)
14

Description

#### Support plan

* *is this issue currently blocking your project?* (yes/no): no
* *is this issue affecting a production system?* (yes/no): no

#### Context

* *node version*: 14.13.1
* *module version with issue*: 17.3.0
* *last module version without issue*: n/a
* *environment* (e.g. node, browser, native): node
* *used with* (e.g. hapi application, another framework, standalone, ...): standalone
* *any other relevant information*:

#### What are you trying to achieve or the steps to reproduce?

I'm using the built-in types and found an inconsistency in the `ValidationResult` type. According to the [API reference](https://joi.dev/api/?v=17.3.0#anyvalidatevalue-options), `validate()` should return the following elements as `ValidationResult`.

> Returns an object with the following keys:
>
> `value` - the validated and normalized value.
> - `error` - the validation errors if found.
> - `warning` - the generated warnings if any.
> - `artifacts` - a `Map` containing any passing rules' artifacts and their corresponding array of paths.

The type specifies the following, in v17.3.0, where `errors` is added, and `artifacts` is not present.

```ts

interface ValidationResult {
error?: ValidationError;
errors?: ValidationError;
warning?: ValidationError;
value: any;
}
```

#### What was the result you got?

Inconsistent `ValidationResult` type.

#### What result did you expect?

Type `ValidationResult` consistent with API.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.