Skip to content

Add support for using keyword (TypeScript 5.2) #1628

Open

Description

@dkhovrich

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?

Activity

  1. fregante commented on Nov 1, 2023

    @fregante

    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?

  2. johnnyreilly commented on Nov 1, 2023

    @johnnyreilly
    Member

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

  3. fregante commented on Nov 1, 2023

    @fregante

    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.

  4. fregante commented on Nov 2, 2023

    @fregante

    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. 👍

  5. dkhovrich commented on Nov 2, 2023

    @dkhovrich
    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.
    
  6. dkhovrich commented on Nov 2, 2023

    @dkhovrich
    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! :)

  7. mfp22 commented on Apr 15, 2024

    @mfp22

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions