4 ms·
From their home page example if(obj.valid === true) { I would flag this line as an error.
by perfunctory 15y ago
From their home page example
if(obj.valid === true) {
I would flag this line as an error.
- inimino 15y agoWhy? obj is specified by the type annotation to be an object with a property 'valid' that is a Boolean, so what's the problem?
- perfunctory 15y agoI just don't like this style very much. It's better to write if (obj.valid) {
- inimino 15y agoSure, 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.
- reginaldo 15y agoSometimes, 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.
- nilved 15y ago`if (foo)` and `if (foo === true)` aren't equivalent.
- Hovertruck 15y agoAccording 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.
- darkxanthos 15y agoWhile uglier === is much more specific and enforces types... Which seems germane here.