microsoft / microsoft/TypeScript
Cannot await Thenable
@rbuckton arbeitet bereits daran.
Seit 17.8.2023.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
🔎 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
💻 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)
🙁 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!
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Bewertung
Dieses Issue wurde noch nicht bewertet.