Interesting, but if I wanted to get this sort of validation I'd just use Google's Closure Compiler. It supports validating types and also lets you do things like casting variables to different types. And the annotation method is pretty clear, flexible, and easy to understand.
What is the license that is free for non-commercial use? Static type checking is nice but implementation in a non-statically-type-checked language is unfortunate.
Sometimes, and I mean just sometimes, it is better to just use ===. For instance, I recently wrote some code where a variable has a value of type Number, but I use "false" to signal the absence of such value (in the sense that the value is not available yet). In that case, I have to use stuff like if(x !== false), because "0" is a valid value in that context.
According to the TypedJS annotation for the function they are. The function definition says that obj.valid has to be a boolean, so any other type of falsy input (0, undefined, null, etc) should never be provided as an argument here.
It would be more interesting if you could also use the annotations to type-check at runtime (optionally). That way if the annotations diverged from the actual code, you'd find out.
22 comments
[ 2.9 ms ] story [ 58.9 ms ] threadif(obj.valid === true) {
I would flag this line as an error.
if (obj.valid) {
Line 180 should be: count += num_arr[i];
Moreover naming accumulation variable for sum "count" is totally counter intuitive.
You don't get the automatic runtime test generation stuff, but that's more along the lines of an add-on utility like Quickcheck/Scalacheck.