kungfooman / RuntimeTypeInspector.js

Checking JSDoc types at runtime for high-quality types - Trust is good, control is better.
MIT License
8 stars 0 forks source link

Refactor validateNumber(...) #67

Open kungfooman opened 10 months ago

kungfooman commented 10 months ago

Currently it has some issues with false positives:

["str", "1", "NaN", NaN, new Date].map(isNaN);
// Outputs: [true, false, true, true, false]

It tests for: undefined / null / NaN / infinity... but it seems we also need a simple typeof check:

validateNumber(["1", 2, 3], 0); // Approved, but it should fail

https://github.com/kungfooman/RuntimeTypeInspector.js/blob/da93e3c51d35df938e33cb695d23af09fa6ad9a6/src-runtime/validateNumber.mjs#L8-L28

And then I also have to fix validateNumber @todo note in validateType.