Symbol.dispose
stage3の
ECMAScript Explicit Resource Management
https://github.com/tc39/proposal-explicit-resource-management
file hendleなどで、自分でcloseする必要がない
Disposable型
https://devblogs.microsoft.com/typescript/announcing-typescript-5-2/
code:ts
function loggy(id: string): Disposable {
console.log(
Creating ${id}
);
return {
Symbol.dispose
() {
console.log(
Disposing ${id}
);
}
}
}
code:tsconfig.json
{
"compilerOptions": {
"target": "es2022",
"lib":
"es2022", "esnext.disposable", "dom"
}
}