News for hackers. Stuff that matters.
Re:TypedJS: Sanity Check your JavaScript by perfunctory on Wednesday February 08, 2012 @03:33AM (#3565761)
From their home page example

if(obj.valid === true) {

I would flag this line as an error.

Re:TypedJS: Sanity Check your JavaScript by inimino on Wednesday February 08, 2012 @05:09AM (#3565969)
Why? obj is specified by the type annotation to be an object with a property 'valid' that is a Boolean, so what's the problem?
Re:TypedJS: Sanity Check your JavaScript by perfunctory on Wednesday February 08, 2012 @06:01AM (#3566065)
I just don't like this style very much. It's better to write

if (obj.valid) {

Re:TypedJS: Sanity Check your JavaScript by reginaldo on Wednesday February 08, 2012 @06:10AM (#3566091)
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.
Re:TypedJS: Sanity Check your JavaScript by nilved on Wednesday February 08, 2012 @06:16AM (#3566099)
`if (foo)` and `if (foo === true)` aren't equivalent.
Re:TypedJS: Sanity Check your JavaScript by Hovertruck on Wednesday February 08, 2012 @10:25AM (#3566846)
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.
Re:TypedJS: Sanity Check your JavaScript by inimino on Wednesday February 08, 2012 @06:08AM (#3566088)
Sure, I agree it is poor style. I guess I assumed because of the context you were saying you would expect the type checker to flag it as an error.
Re:TypedJS: Sanity Check your JavaScript by darkxanthos on Wednesday February 08, 2012 @08:46AM (#3566478)
While uglier === is much more specific and enforces types... Which seems germane here.