There is a JavaScript proposal for using Symbol.dispose as a way to automatically clean up resources. You do that by declaring variables like so:
using resource = new Resource();
The variable resource will be automatically disposed when it goes out of scope. We used to have our own dispose method and with helper method that allows scoped access to the resource, before it gets cleaned up at the end. TypeScript already fully implements and polyfills support for it, so we can already fully switch over to it.
There is a JavaScript proposal for using
Symbol.dispose
as a way to automatically clean up resources. You do that by declaring variables like so:The variable
resource
will be automatically disposed when it goes out of scope. We used to have our owndispose
method andwith
helper method that allows scoped access to the resource, before it gets cleaned up at the end. TypeScript already fully implements and polyfills support for it, so we can already fully switch over to it.