microsoft / microsoft/TypeScript

Cannot await Thenable

Aperta
#55,408 9 commenti 3 reazioni 1 assegnatario Vedi su GitHub

@rbuckton ci sta già lavorando.

Dal 17/8/2023.

Needs Investigation
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

🔎 Search Terms

"Type of 'await' operand must either be a valid promise or must not contain a callable 'then' member.", "TS1320"

🕗 Version & Regression Information
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about async
⏯ Playground Link

https://www.typescriptlang.org/play?target=9#code/PTAEAEBcEMCcHMCmkBcoCiBlATABm9gFCEDGA9gHYDOkoAtgJ4AqAFohdAEYA2ioAvKADehUKEhsKACkoAxAK7cAZgEtuvACYAaUJQBKiAFaISkRBoCUQ0LGTzYFXRQXK1mgPwA6KQEYLoAF9CIMJoKgYKElAleUjIFUpQaDpoFWl-ETFQcmpaWAEkgHdU2kZWdi5eAG5RMRyqMl5PbjJ4KQByADdobnlEdp1YHXaUAfEGAAdEMiUbCxqs20h7R1gakLLJSr4qaHiqVUQqUAAFWDI6FSpEABkVAGtEAB4KeTpORFgAPmJryCYVHRpvJIFJkqkKDpcBYgA

💻 Code
// @target: ES2022

const myThenable = {
  then(onFulfilled, onRejected){ return onFulfilled?.(1) }
}

async function amain() {
   const r = await myThenable;
   console.log('value', r, ':', typeof r);
   return r;
}

myThenable satisfies PromiseLike<number>

setTimeout(amain, 0)

Workbench Repro

🙁 Actual behavior

An error is shown:

Type of 'await' operand must either be a valid promise or must not contain a callable 'then' member.

🙂 Expected behavior

I expect no error or a suppressible warning. I also expect some explanation of "why" or a suggestion like "wrap the thenable in a Promise.resolve()"

Additional information about the issue

This is valid JavaScript, and executes in Deno, Node, Chrome, and Firefox.

Note that await doesn't even require its argument to be a PromiseLike - then may have return type void or even never!

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.