Editorial: note that Promise<T> arguments also accept T · whatwg/webidl@e1300e9
tabatkins
·
2026-03-27
·
via Recent Commits to webidl:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -8582,6 +8582,24 @@ IDL [=promise type=] values are represented by JavaScript [=PromiseCapability=]
|
8582 | 8582 | IDL [=promise type=] represents. |
8583 | 8583 | </p> |
8584 | 8584 | |
| 8585 | +<div class=note> |
| 8586 | + |
| 8587 | + When converting a JS value to a <code>Promise<T></code> IDL value, |
| 8588 | + first the value is wrapped in an (IDL) Promise, |
| 8589 | + then later machinery ensures the promise correctly resolves |
| 8590 | + to a value of type <code>T</code>. |
| 8591 | + |
| 8592 | + This means that, for example, |
| 8593 | + a method defined to take a <code>Promise<T></code> argument |
| 8594 | + will automatically accept both {{Promise}} objects |
| 8595 | + (which must eventually resolve to a <code>T</code> object) |
| 8596 | + and <code>T</code> objects themselves. |
| 8597 | + |
| 8598 | + (It will also, initially, accept <em>any other</em> type of object, |
| 8599 | + but will eventually auto-reject the promise |
| 8600 | + for resolving to the wrong type.) |
| 8601 | +</div> |
| 8602 | + |
8585 | 8603 | <h5 id="js-promise-manipulation" oldids="es-promise-manipulation">Creating and manipulating Promises</h5> |
8586 | 8604 | |
8587 | 8605 | <div algorithm> |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。