News for hackers. Stuff that matters.
Re:JavaScript Equality Minesweeper by DougBTX on Monday September 17, 2018 @05:37AM (#18004382)
I'm interested to know what people think about this with TypeScript - quite a lot of the weird behaviour in plain JS is rejected by the compiler, eg, "true == 1" evaluates to true in plain JS, but is a compiler error in TypeScript since it rejects bool vs number equality checks.

So with TypeScript code, I've been continuing to use == as in most other languages, with the expectation that any odd comparisons will be flagged by the compiler. On the other hand, I've not verified myself that it catches them all, so I wonder if anyone has come across other edge cases with this that could cause problems down the line.

Re:JavaScript Equality Minesweeper by slikts on Monday September 17, 2018 @05:42AM (#18004406)
The issue there is that TS allows dropping out of the type system with `any`, so it might not actually be checking the types you're comparing, so I'd still use ===.
Re:JavaScript Equality Minesweeper by kbp on Monday September 17, 2018 @07:09AM (#18004789)
I prefer it when Typescript tries to provide static type checking for Javascript rather than providing checking for how they wish Javascript was. `(x: number, y: string) => x == y` is an error because 'this condition will always return false'. In what language? There are linter rules for enforcing === over ==; Typescript having incorrect type definitions to try and make sure you only use == like === seems like a really poor solution to that.
Re:JavaScript Equality Minesweeper by Sacho on Monday September 17, 2018 @07:28AM (#18004864)
Aren't you implicitly assuming that TS's number === JS's Number and TS's string === JS's String? You could say == is extended for TS's types(number/string), but the JS == still exists: x as any == y as any;
Re:JavaScript Equality Minesweeper by kbp on Monday September 17, 2018 @10:46AM (#18006360)
I can see what you're saying, but I think that argument would be a lot stronger if == compiled to ===. If you want an operator with ==='s semantics, it's there; providing == and claiming it behaves like === just seems like an opportunity for annoying surprises if something slips through the cracks. Since == doesn't compile to ===, I wouldn't use it unless I understood its semantics and wanted them.
Re:JavaScript Equality Minesweeper by arisb on Monday September 17, 2018 @08:32AM (#18005275)
I'm guessing you can't use `(x: number, y: string) => x === parseInt(y)`?
Re:JavaScript Equality Minesweeper by jaaames on Monday September 17, 2018 @09:19AM (#18005639)
As long as you feed parseInt it's second radix parameter you can :p