diff --git a/src/lualib/Using.ts b/src/lualib/Using.ts index c61d544eb..a720f6e60 100644 --- a/src/lualib/Using.ts +++ b/src/lualib/Using.ts @@ -1,6 +1,6 @@ export function __TS__Using( this: undefined, - cb: (...args: TArgs) => TReturn, + cb: (this: void, ...args: TArgs) => TReturn, ...args: TArgs ): TReturn { let thrownError; diff --git a/test/unit/using.spec.ts b/test/unit/using.spec.ts index 5182b8928..34b4fef67 100644 --- a/test/unit/using.spec.ts +++ b/test/unit/using.spec.ts @@ -193,3 +193,27 @@ test("await using no extra diagnostics (#1571)", () => { } `.expectToHaveNoDiagnostics(); }); + +// https://github.com/TypeScriptToLua/TypeScriptToLua/issues/1584 +test("works with disposable classes (#1584)", () => { + util.testFunction` + const log = []; + + class Scoped { + action(): void { + log.push("action") + } + [Symbol.dispose]() { + log.push("cleanup") + } + } + + function TestScoped(): void { + using s = new Scoped(); + s.action(); + } + + TestScoped(); + return log; + `.expectToEqual(["action", "cleanup"]); +});