microsoft / microsoft/TypeScript

Cannot await Thenable

Abierto
#55,408 9 comentarios 3 reacciones 1 asignado Ver en GitHub

@rbuckton ya está trabajando en esto.

Desde el 17/8/2023.

Needs Investigation
Lenguaje dominante
Go
Estrellas
111k
Forks
14.4k
Merge medio
1 d 19 h
PR fusionados (30 d)
117

Descripción

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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.