4 ms·
The one I want is pattern matching (https://tc39.es/proposal-pattern-matching/ https://tc39.es/proposal-pattern-matching/), which is still at stage 1 so many ye
by dkdbejwi383 2y ago
The one I want is pattern matching (https://tc39.es/proposal-pattern-matching/ https://tc39.es/proposal-pattern-matching/), which is still at stage 1 so many years away, sadly.
- halfmatthalfcat 2y agoPattern matching (and expression based assignment, of which idk if there’s a proposal for or not) are two things that would really drive a ton of value.
- CharlieDigital 2y agoIt's going to end up looking a lot like C# [0][1]; these two/three (JS/TS, C#) languages have been converging for a while now. Now just waiting for C# to get official first party discriminated unions! [0] https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/patterns https://learn.microsoft.com/en-us/dotnet/csharp/language-ref... [1] https://timdeschryver.dev/blog/pattern-matching-examples-in-csharp https://timdeschryver.dev/blog/pattern-matching-examples-in-...
- adabyron 2y agoJust an FYI for those unaware TS & C# are both creations of Anders Hejlsberg & his colleagues at Microsoft. Both are some of my favorite languages as well. We would all benefit if JS was more like C# in my opinion.
- recursive 2y agoAssignment is already an expression, no? console.log(x = "hello");
- 65 2y agoNow try it with a constant: console.log(const x = "hello"); Doesn't work.
- recursive 2y agoThat's a declaration. That would be cool. Doesn't currently work with let or var either.
- 65 2y agoI think this is basically assigning values to the window object, similar to updating values in any object. e.g. const a = { b: 1 } console.log(a.b = 2); // logs 2
- recursive 2y agoOnly if you haven't already declared the variable. e.g. let x; console.log(x = 'hello'); My point is that the `x = 'hello'` part is an assignment, and an expression, and has the exact same semantics regardless of whether you use that expression as a statement. So, assignments would seem to be expressions.
- hajile 2y agoI also REALLY want records and tuples.
- DanielHB 2y agoUnfortunately that proposal seems to be kinda dead. React is a fundamentally flawed framework because of the lack of this feature. It inverts the responsibility of any non-primitive prop by putting the burden on the parent element instead of the child to decide when to rerender things. So elements are no longer self-contained if they receive any non-primitive values (besides react elements). The React compiler auto-memoization that facebook is pushing also addresses this issue through build-time magic. I not fond of this approach.