Can you post exactly what you’re running?
What is value? Where does it come from?
Just to be sure I tested these and got this result:
let value;
// Scenario 1
value='gfdgdfgdf';
check('gfdgdfgdf', Number)
=> Uncaught errorClass {message: "Match error: Expected number, got string", ...}
// Working correctly
// Scenario 2
value=123;
check(value, Number)
=> undefined
// Working correctly
// Scenario 3
value='&*$%#HJHDS'
let regexp = '/^[a-z0-9]+$/i';
check(value, String, Match.Where(value => regexp.test(value)));
=> Uncaught ReferenceError: value is not defined
// Because check only takes two arguments, re-write:
check(value, Match.Where(value => regexp.test(value)));
=> Uncaught TypeError: regexp.test is not a function
// Because regexp is a string, not a regex. rewrite:
regexp = /^[a-z0-9]+$/i; // no quotes so it's a regexp literal
check(value, Match.Where(value => regexp.test(value)));
=> Uncaught errorClass {message: "Match error: Failed Match.Where validation", ...}
// Working correctly
// Scenario 3 part 2
// With fixes from before:
value='&*$%#HJHDS'
Match.Where(function(value){
check(value, String);
let regexp = /^[a-z0-9]+$/i;
return regexp.test(value);
});
=> Where {condition: ƒ}
// returns a validator function we can pass to check
check(value, Match.Where(function(value){
check(value, String);
let regexp = /^[a-z0-9]+$/i;
return regexp.test(value);
}));
=> Uncaught errorClass {message: "Match error: Failed Match.Where validation", ...}
// Works correctly
I’m guessing it’s something about how you are passing value, maybe add a breakpoint and test the typeof value before continuing