Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Numbers that are strings are marked as invalid #345

Open
adwydman opened this issue Mar 3, 2021 · 0 comments
Open

Numbers that are strings are marked as invalid #345

adwydman opened this issue Mar 3, 2021 · 0 comments

Comments

@adwydman
Copy link

adwydman commented Mar 3, 2021

Let's say I have a the following object and validator configuration:

const myObject = {
  age: "24"
};
{
  age: {
    type: "number",
    numericality: {
      greaterThan: 0
    }
  }
}

The configuration will return an error Age must be of type number. The problem is that the documentation states:

Per default strings are coerced to numbers using the + operator.

While this is true, the logic has no chance of being hit - the type check is triggered first and throws an error.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant