A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/typescript-eslint/typescript-eslint/issues/8255 below:

`require-using` to force using `using` with disposable · Issue #8255 · typescript-eslint/typescript-eslint · GitHub

Before You File a Proposal Please Confirm You Have Done The Following... My proposal is suitable for this project Description

TypeScript now supports Disposables: objects that have some "dispose" behavior when they go out of scope.

It's important to use using and not const/let when using those objects, otherwise the automatic cleanup does not happen and you would leak resources.

Fail Cases

In this case we are opening a file through an API that expects to be disposed, but we are not using it as such. The readConfig function will thus leak resources associated to the opened file.

declare function openFile(url: string): Disposable & MyFileAPI;

function readConfig() {
  const configFile = openFile("./configFile");
  return configFile.contentsAsJson();
}
Pass Cases

In this case we are properly disposing the file resource.

declare function openFile(url: string): Disposable & MyFileAPI;

function readConfig() {
  using configFile = openFile("./configFile");
  return configFile.contentsAsJson();
}
Additional Info

This is the equivalent to require-await, but for Disposables rather than Thenables.

auvred, Yona-Appletree, maxdavidson, kirkwaiblinger, eldiGH and 30 more


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4