FR: Add `Disposable` interface to `Component` class

TypeScript 5.2 introduced Disposable interface

It would be great to adopt this semantics:

class Component implements Disposable {
  // ...

  public [Symbol.dispose]() {
    this.unload();
  }
}

so you can do

using const myComponent = new MyComponent();
myComponent.method1();
myComponent.method2();
// it's automatically unloaded at the end of the block

I acknowledge that Obsidian types might be used by pre-5.2 TypeScript users, so some polyfills might be required.

2 Likes