Skip to content

Auto-insert await for property accesses on Promise #31450

Description

async function foo(x: Promise<string>) {
  x./**/
}

Go to the /**/ marker and request completions.

The proposal here is that all the completions for string should show up. When the user selects a string member, we should automatically await the value, so selecting toLowerCase changes the code to (await x).toLowerCase.

Activity

  1. fatcerberus commented on May 18, 2019

    @fatcerberus

    This seems like a good idea but should only be done inside async functions if possible. In the example above, the function is not async so adding an await there would make the code invalid.

  2. DanielRosenwasser commented on May 18, 2019

    @DanielRosenwasser
    MemberAuthor

    Yes, thank you, that was one of the subtler points I forgot to add to this issue. It would be incredibly annoying/unsafe otherwise.

  3. fatcerberus commented on May 18, 2019

    @fatcerberus

    Something else I just thought of: since this would be done via autocompletion, the feature probably shouldn't get any ideas about automatically converting the function to async - doing so is a breaking change in most cases since it forces the function into returning a promise.

  4. DanielRosenwasser commented on May 22, 2019

    @DanielRosenwasser
    MemberAuthor

    Spoke with Daniel Ehrenberg (@littledan) today, and once top-level await lands, we should consider doing this at the top level based on target and module options.

  5. andrewbranch commented on Jun 26, 2019

    @andrewbranch
    Member

    Related: #30646

  6. andrewbranch commented on Jun 26, 2019

    @andrewbranch
    Member

    /cc Brian Terlson (@bterlson): Thoughts on this (and the work done already at #32101) as a partial solution for #30646? Personally, I’d still like to surface a quick fix and make sure we have a really good diagnostic message in addition to this, but I think completions are a good first line of defense for the last bullet point you mentioned:

    • The target of a member expression and T has the member (or maybe the property name is not in Promise).
  7. bterlson commented on Jun 26, 2019

    @bterlson
    Member

    I like it a lot, personally. Incrementally addressing the various bullets is fine by me, and I think this is probably one of the biggest rocks.

  8. 1 remaining item

  9. Kingwl commented on Jun 27, 2019

    @Kingwl
    Contributor

    Another quick fix is better, the current completion behavior seems cannot add async modifier simply as far as I know

  10. xujif commented on Aug 13, 2019

    @xujif

    a suggestion: add a new keyword to a function and translate to js with await all variables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Domain: LS: Completion ListsThe issue relates to showing completion lists in an editorEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Fix AvailableA PR has been opened for this issueSuggestionAn idea for TypeScript

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions