5 ms·
TypeScript got `!= null` wrong. In Flow (and CoffeeSript) null and undefined are treated the same, and `!= null` is preferred. You do not want to deal with code
by xixixao 6y ago
TypeScript got `!= null` wrong. In Flow (and CoffeeSript) null and undefined are treated the same, and `!= null` is preferred. You do not want to deal with code that treats null and undefined differently.
Otherwise this is a great list!
- recursive 6y agoOne of the foundational philosophies of typescript is that the language does not have different semantics than javascript, so that wasn't an option.
- xixixao 6y agoNah. This doesn’t change the semantics of JS. As numerous sibling commentors pointed out, distinguishing between null and undefined is not a good idea in normal JS either. This was simply a bad design decision in TS, especially given that CoffeeScript has done it “right” many years before. Unfortunately I feel like every language design team prefers to learn their mistakes on their own instead of learning from others (with the usual “our language is different” excuse).
- seniorsassycat 6y agoI think the suggestion is for typescript to have one none type equal to undefined | null. The type checker could not error on undefined when null is required or vice versa. Then code should use != null comparisons which match the none types semantics without needing runtime code generation. I think this would violate another typescript principles that existing libraries and patterns should be expressable in typescript. Some schmuck wrote a library that accepts null but not undefined so typescript has to distinguish them.
- EugeneOZ 6y agoI do want.