using
Symbol.dispose
https://zenn.dev/ventus/articles/ts5_2-using-preview
https://www.totaltypescript.com/typescript-5-2-new-keyword-using
code:ts
{
const getResource = () => {
// リソースの初期化処理
...
return {
Symbol.dispose
: () => {
// リソースを開放する処理
}
}
}
using resource = getResource(); // usingで選言。
} // ↑スコープ出る直前にdisposeが呼ばれる