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 missing awaits when destructuring properties from a promisified type #57831

Open
Andarist opened this issue Mar 18, 2024 · 2 comments
Open
Labels
Experience Enhancement Noncontroversial enhancements Help Wanted You can do this Suggestion An idea for TypeScript
Milestone

Comments

@Andarist
Copy link
Contributor

Andarist commented Mar 18, 2024

πŸ”Ž Search Terms

missing await destructuring codefix promise promisified members properties

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried

⏯ Playground Link

https://www.typescriptlang.org/play?#code/JYOwLgpgTgZghgYwgAgKoGdrIN4ChnLAAmAXMumFKAOYDc+yIcAthGRVSHbgL665EICADZwoKGAFcQCMMAD2IZNQhgM0ABQBKMgAUo85sEwAedVAB89XHHQBPGciky5i5JAracDBIoqMWFABeZVVzbQA6AHoAKgBGGKjrAl8Qf2xkWIAmROQeZBCVNUwobXoeIA

πŸ’» Code

interface User {
  id: string;
  name: string;
}

declare function getUser(): Promise<User>;

async function test() {
  const name = getUser()./*1*/;

  const { /*2*/  } = getUser();
}

πŸ™ Actual behavior

with preferences.includeCompletionsWithInsertText at marker 1 we get completions for id and name and the line gets auto-fixed for us:

const name = (await getUser()).name

Nothing like that happens at marker 2 - no completions, no auto-fixes

πŸ™‚ Expected behavior

It would be cool if the second would work like the first one in this regard. It could go from:

  const { /*2*/  } = getUser();

to

  const { name } = await getUser();

Additional information about the issue

it's a feature request but the bug report template just worked the best here πŸ˜‰

@fatcerberus
Copy link

fatcerberus commented Mar 18, 2024

I think the playground link is getting eaten... by some... linux or something

Just to be clear, the expected behavior is

const { name } = await getUser();

correct? I wasn't totally clear on whether you wanted the await on the RHS or on the properties themselves (since you said "missing awaits" plural). Although I guess you can't use await on the LHS of a destructuring...

@Andarist
Copy link
Contributor Author

I think the playground link is getting eaten... by some... linux or something

Fixed, thanks for calling it out.

correct? I wasn't totally clear on whether you wanted the await on the RHS or on the properties themselves (since you said "missing awaits" plural). Although I guess you can't use await on the LHS of a destructuring...

Yes, correct. I've added this exact expected result in code form so it should be clear now.

@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript Experience Enhancement Noncontroversial enhancements labels Mar 18, 2024
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Mar 18, 2024
@RyanCavanaugh RyanCavanaugh added the Help Wanted You can do this label Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Experience Enhancement Noncontroversial enhancements Help Wanted You can do this Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants