hapijs / joi

The most powerful data validation library for JS
Other
20.89k stars 1.51k forks source link

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

Open KristjanTammekivi opened 11 months ago

KristjanTammekivi commented 11 months ago

Support plan

Context

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

interface User2 {
  id?: number
}

Joi.object<User2, true>({
  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