Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lualib/Using.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export function __TS__Using<TArgs extends Disposable[], TReturn>(
this: undefined,
cb: (...args: TArgs) => TReturn,
cb: (this: void, ...args: TArgs) => TReturn,
...args: TArgs
): TReturn {
let thrownError;
Expand Down
24 changes: 24 additions & 0 deletions test/unit/using.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]);
});