Defines the contract for objects that can be disposed to release resources.
This interface allows for simple type checking that includes types that don't
explicitly declare themselves as implementing this interface but do have a
dispose() method. This enables structural typing for disposal operations.
Example
classDatabaseConnectionimplementsDisposable { dispose(): void { // Close connection and release resources } }
// Can also work with objects that have dispose method without explicit implementation constsomeObject = { dispose() { console.log('Cleaning up...'); } }; // someObject is structurally compatible with Disposable
Defines the contract for objects that can be disposed to release resources.
This interface allows for simple type checking that includes types that don't explicitly declare themselves as implementing this interface but do have a dispose() method. This enables structural typing for disposal operations.
Example