4 ms·
This is not TypeScript-specific, it’s a stage-3 ECMA-262 proposal. https://github.com/tc39/proposal-explicit-resource-management/ https://github.com/tc39/propo
by pwdisswordfishc 3y ago
This is not TypeScript-specific, it’s a stage-3 ECMA-262 proposal.
https://github.com/tc39/proposal-explicit-resource-management/ https://github.com/tc39/proposal-explicit-resource-managemen...
It’s a shame the author insisted on it looking like C# and sabotaged attempts to combine disposal with destructuring.
Also, there is no move operator without futzing around with DisposableStack. Though that could be introduced later; it’s not a day-zero design issue.
- ignoramous 3y agoTFA mentions as much: TypeScript 5.2 will introduce a new keyword - 'using' - that you can use to dispose of anything with a Symbol.dispose function when it leaves scope. This is based on the TC39 proposal, which recently reached Stage 3, indicating that it is coming to JavaScript.
- paraboul 3y agoAgreed with OP, the title is misleading. Typescript technically doesn't introduce any new runtime feature. This is basically a polyfill for an upcoming Javascript feature.
- franciscop 3y agoNo, I am very familiar with JS and wasn't sure reading the article what bits were the new TC39 proposal and what bits were TS-specific. It seems, from having read it once quickly, that it's just TS adding support early to a feature that will come in JS, similar to how you could add support to async/await in your transpiler before they were commonplace by transforming them into promises back in the day. But that's definitely not a "TS new keyword".
- Dylan16807 3y agoFrom a brief search, it looks like the semantics around destructuring and what exactly gets disposed were causing confusion? What's the not-C#-like method that would have allowed destructuring in a better way?
- hn_throwaway_99 3y ago> and sabotaged attempts to combine disposal with destructuring. Can you explain by what you mean by this? What would "disposal combined with destructuring" look like?
- potsandpans 3y agothis happens a lot in tc39 proposals unfortunately.
- scarab92 3y agoThe overwhelming share of improvements made to Java, Javascript, Typescript etc over the past decade have been inspired by C#, so I can understand why the C# terminology was front of mind. Can you elaborate more of what combining disposal and destructuring would look like?
- vips7L 3y agoI’m not sure Java has taken anything from C#. Most of its recent features have been taken from ML influences.