Am I missing the point or is the “using” thing just a very over-engineered destructor that you can FORGET to call? It’s nothing like Python’s “with” that lets you define a scope for an object to be destructed early. If you forget, or simply don’t know that the object supports “disposal”, will the object simply never be disposed? Or will the TSC not compile if you leave out a “using” for a disposable object?
> It’s nothing like Python’s “with” that lets you define a scope for an object to be destructed early.
You can forget to use `with` as well. Destructors in python are called when the reference count hits zero or during a gc pass. These new typescript destructors apply to the variable, not the object, so they run when the variable goes out of scope, regardless of what other references there might be to the same object. If you want to emulate `with` more closely, you can create a new scope for your `using` declaration, and put it at the very top of that new scope.
TSC should fail the build if it doesn't have the destruction interface, the scope is the scope the variable is initialized in/under. It's very similar to C#'s usage of using.
Edit: It's also a pending Stage 3 proposal for EcmaScript.
TypeScript's ability to detect problems in the code seems superior than what Visual Studio ships with for C# - for example it doesn't warn about forgetting to `await` a method call.
Because it will run in JS and you can do stuff like return something with a lifetime to be scoped at a higher level. Is there too declare intent. Typescript is just really advanced linting.