Microsoft/TypeScript

Add missing awaits when destructuring properties from a promisified type

Open

#57.831 geöffnet am 18. März 2024

Auf GitHub ansehen
 (2 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)TypeScript (6.726 Forks)batch import
Experience EnhancementHelp WantedSuggestion

Repository-Metriken

Stars
 (48.455 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 6T 17h) (9 gemergte PRs in 30 T)

Beschreibung

🔎 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 😉

Contributor Guide