Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for using keyword (TypeScript 5.2) #1628

Open
dkhovrich opened this issue Sep 8, 2023 · 7 comments
Open

Add support for using keyword (TypeScript 5.2) #1628

dkhovrich opened this issue Sep 8, 2023 · 7 comments

Comments

@dkhovrich
Copy link

TypeScript has introduced a new keyword using in 5.2 release. Seems like ts-loader does not support it. I get the following error:

You may need an additional loader to handle the result of these loaders.
> await using tempFile = await createTempFile(content.value);

Could you please add support for this new keyword?

@fregante
Copy link

fregante commented Nov 1, 2023

What's causing this issue? It seems that TS 5.2 is already supported and tested (#1633), so how come ts-loader also needs to be updated?

@johnnyreilly
Copy link
Member

Suspect this may be a tsconfig.json issue. No change should be required to ts-loader

@fregante
Copy link

fregante commented Nov 1, 2023

You may be right, for some reason tsc itself is failing on the files, even if I use the suggested TypeScript config:

{
    "compilerOptions": {
        "target": "es2022",
        "lib": ["es2022", "esnext.disposable", "dom"]
    }
}

Seen at the bottom of the section https://devblogs.microsoft.com/typescript/announcing-typescript-5-2/#using-declarations-and-explicit-resource-management

My config is based on @sindresorhus/tsconfig.json.

@fregante
Copy link

fregante commented Nov 2, 2023

The error is between the chair and the monitor. 😅

The syntax is:

using tempFile = await createTempFile(content.value);

not

await using tempFile = await createTempFile(content.value);

I think ts-loader is working correctly here. 👍

@dkhovrich
Copy link
Author

The syntax is correct when you are using Symbol.asyncDispose. Please take a look at this simplified example from the handbook:

async function doWork() {
    // Do fake work for half a second.
    await new Promise(resolve => setTimeout(resolve, 500));
}
function loggy(id: string): AsyncDisposable {
    console.log(`Constructing ${id}`);
    return {
        async [Symbol.asyncDispose]() {
            console.log(`Disposing (async) ${id}`);
            await doWork();
        },
    }
}
async function func() {
    await using a = loggy("a");
}
func();

And it works as expected when I compile it with esbuild. But Webpack with ts-loader keeps failing with an error:

You may need an additional loader to handle the result of these loaders.

@dkhovrich
Copy link
Author

Hm, I could make it work with no error after I changed compilerOptions.target from ESNext to es2022.
A bit weird, but I think that's okay.
Thanks! :)

@mfp22
Copy link

mfp22 commented Apr 15, 2024

Does this new keyword collide with my favorite undocumented RxJS function using? Since I haven't found documentation when I've looked for it in the past, I'm always concerned there could be a breaking change with it at some point

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants