Skip to content

AsyncDisposable should allow non-Promise returning implementations #63299

@mfulton26

Description

@mfulton26

⚙ Compilation target

esnext

⚙ Library

lib.esnext.disposable.d.ts

Missing / Incorrect Definition

AyncDisposable doe not allow for a non-Promise returning implementation.

Current:

interface AsyncDisposable {
    [Symbol.asyncDispose](): PromiseLike<void>;
}

Suggested:

interface AsyncDisposable {
    [Symbol.asyncDispose](): void | PromiseLike<void>;
}

Sample Code

// valid:
await using disposableAsync = { async [Symbol.asyncDispose]() {} };

// valid but flagged by TS as invalid:
await using disposable = { [Symbol.asyncDispose]() {} };
// The initializer of an 'await using' declaration must be either an object with a '[Symbol.asyncDispose]()' or '[Symbol.dispose]()' method, or be 'null' or 'undefined'.
//   Type '{ [Symbol.asyncDispose](): void; }' is not assignable to type 'AsyncDisposable'.
//     The types returned by '[Symbol.asyncDispose]()' are incompatible between these types.
//       Type 'void' is not assignable to type 'PromiseLike<void>'.

Documentation Link

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncDispose#:~:text=This%20method%20can%20return%20a%20promise%2C%20which%20will%20be%20awaited%20before%20continuing. ("can", not "must")

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions