The using keyword does not work properly when combined with async. Take the following typescript code:
async function getResource(): Promise<AsyncDisposable> {
return {
[Symbol.asyncDispose]: async () => {
console.log("Dispose async!");
}
};
}
async function someOtherAsync() {
// Do async work...
}
async function main() {
await using resource = await getResource();
await someOtherAsync();
}
main();
This code compiles and works as expected. However, attempting to compile this with tstl results in the following errors:
Await can only be used inside async functions.(typescript-to-lua)
The error happens at await someOtherAsync(), presumably because the way tstl compiles the using keyword does not account for the function being async in the protected call.
The using keyword does not work properly when combined with async. Take the following typescript code:
This code compiles and works as expected. However, attempting to compile this with
tstlresults in the following errors:The error happens at
await someOtherAsync(), presumably because the waytstlcompiles theusingkeyword does not account for the function being async in the protected call.