hapijs / hapijs/joi

Incorrectly loose types for strict object schema for non-string values

Open
#2,995 0 comments 0 reactions 0 assignees View on GitHub
support
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*: 20.0.5
* *module version with issue*: 17.11.0, master branch
* *last module version without issue*:
* *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?

```ts
interface User2 {
id?: number
}

Joi.object({
id: Joi.string().optional()
});
```

#### What was the result you got?

No warning despite id being string

#### What result did you expect?

Typescript warning that string schema is not assignable to number schema

This seems to work as a fix, I would create a PR but I couldn't get the test to work correctly, it still said `Expected an error` even though after the change TypeScript warned about it
![image](https://github.com/hapijs/joi/assets/8754356/4eb2311c-67e9-4880-92a1-664a11556662)

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.