Live data from Hacker News

TypeScript 5.2 Beta

devblogs.microsoft.com

11–12 of 12 posts

Re: TypeScript 5.2 Beta

#11

I had mixed feelings about using, but I’m into it now. I like seeing familiar conventions from other languages I’ve come to love, and it seems like the implementation will likely deliver the same QOL benefits I’m familiar with. On that note, I know it’s contentious, but I’d love to see pattern matching baked in like we have it in Rust (or similar). I’ve come to love ts-pattern so much, and I’m constantly wishing it w…

[deleted]

Re: TypeScript 5.2 Beta

#12
post #10
post #9

I can't help but think this is a clunkier than necessary. With function composition and the try/finally approach described we can get the same thing: const doSomeWork = () => { // some computation here. } const withCleanup = (fn, cleanupFn) => { let x; try { x = fn() } finally { cleanupFn() } return x; }; const someCleanupFn = () => { // remove that file or whatever... }; const doSomeWorkAndCleanup = withCleanup(doSo…

How would I access anything locally created inside doSomeWork from my someCleanupFn in this example?

Arguments to the doSomeWork can be carried through to someCleanupFn as can any return values from doSomeWork.

If doSomeWork returns all the pieces that need to be cleaned up by someCleanupFn (or those pieces are part of the original arguments), then those values can also be passed in as arguments to someCleanupFn.

This pattern (passing original arguments through, along with return values, to a supporting function) hints at a more elegant solution as well - a new monadic structure that supports this behavior by default.

Post reply on HN