Skip to content

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

Open
@KristjanTammekivi

Description

@KristjanTammekivi

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?

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    supportQuestions, discussions, and general support

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions