hapijs / hapijs/joi

Incorrect types for joi.expression and LanguageMessages

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

Description

### Module version

17.13.3

### What documentation problem did you notice?

#### joi.expression type documentation
According to [the docs](https://joi.dev/api/?v=17.13.3#expressiontemplate-options---aliases-x), the second optional argument `options` is the same as the options for `joi.ref` with an additional `functions` object. This isn't reflected in the `.d.ts` file [here](https://github.com/hapijs/joi/blob/master/lib/index.d.ts#L2263).

I think it should be something like:

```
expression(template: string, options?: ReferenceOptions & { functions: Record})
```

#### LanguageMessages type documentation
LanguageMessages is [typed](https://github.com/hapijs/joi/blob/master/lib/index.d.ts#L29C5-L29C77) as `type LanguageMessages = Record>;` but the record value could also be a `joi.expression()`, correct?

I'm using Joi like this below and it seems to be happy, although the types aren't.

```
import lowerFirst from 'lodash/lowerFirst.js'

export const messages: LanguageMessages = {
'string.base': joi.expression('Enter {{lowerFirst(#label)}}', { functions: { lowerFirst }})
}
```

Before I submit a PR, do you agree the types are incorrect?

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.