Skip to content

Being able to omit the variable name when doing {#await promise then value} {/await} #6476

Closed
@aradalvand

Description

@aradalvand

Describe the problem

Suppose you have a promise that doesn't return anything (i.e. Promise<void> in TypeScript terms). If you want to use Svelte's await syntax for such a promise, you can do so with separate {#await} {:then} blocks, and you're perfectly allowed to omit the variable name in the {:then} block, like so:

{#await someVoidPromise}
  Waiting...
{:then}
  Done.
{/await}

Svelte also provides an alternative syntax for when you don't want to show anything until the promise is resolved. It looks like this:

{#await somePromise then value}
    Done: {value}
{/await}

Explained in the official tutorial here.

Unlike what I expected, you cannot use the above syntax with a void promise, in other words you can't omit the variable name, so you can't do:

{#await someVoidPromise then}
    Done.
{/await}

You'd get the following error:

image

Describe the proposed solution

I think the aforementioned syntax should be supported. You should be able to omit the variable name after then when you don't have a separate {#await} block, just like you can do so when you do have a separate {#await} block.

Alternatives considered

You'd have to do the following, and have an empty {#await} block:

{#await someVoidPromise}
{:then}
  Done.
{/await}

which isn't nice.

Importance

would make my life easier

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions