-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Cannot await Thenable #55408
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Your
It is suppressible using |
It’s also suppressible with Some things like |
Those are about stylistic choices, not actual type errors. But I agree that the error message could be better. |
It's not correct to type
(async ()=>{
const result = await ({then:(f,r)=>{console.log('onFulfilled returned:',f(1))}})
console.log('promise resolved to:',result)
})() For me, the above prints:
EDIT: maybe you meant |
Not sure if related, but this also fails for reasons I don't understand: interface MaybeThenable {
then?: PromiseLike<any>["then"];
}
async (myThenable: MaybeThenable) => {
if (myThenable.then) {
await myThenable;
}
} The error message:
|
It's not a discriminated union and this property refinement doesn't get "transferred" on the object itself once you pass that object into a function (and |
You don't need to refine actually: interface MaybeThenable {
then?: PromiseLike<any>["then"];
}
async (myThenable: MaybeThenable) => {
await myThenable;
} Either: A) |
Ah, I see. |
Is there any progress? |
🔎 Search Terms
"Type of 'await' operand must either be a valid promise or must not contain a callable 'then' member.", "TS1320"
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play?target=9#code/PTAEAEBcEMCcHMCmkBcoCiBlATABm9gFCEDGA9gHYDOkoAtgJ4AqAFohdAEYA2ioAvKADehUKEhsKACkoAxAK7cAZgEtuvACYAaUJQBKiAFaISkRBoCUQ0LGTzYFXRQXK1mgPwA6KQEYLoAF9CIMJoKgYKElAleUjIFUpQaDpoFWl-ETFQcmpaWAEkgHdU2kZWdi5eAG5RMRyqMl5PbjJ4KQByADdobnlEdp1YHXaUAfEGAAdEMiUbCxqs20h7R1gakLLJSr4qaHiqVUQqUAAFWDI6FSpEABkVAGtEAB4KeTpORFgAPmJryCYVHRpvJIFJkqkKDpcBYgA
💻 Code
Workbench Repro
🙁 Actual behavior
An error is shown:
🙂 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 aPromiseLike
-then
may have return typevoid
or evennever
!The text was updated successfully, but these errors were encountered: