You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Expected behavior: Adding a type declaration should not affect the behavior of the example. An error should be thrown in both cases or neither.
Actual behavior: Adding a type declaration causes the error Type 'StringPromise' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value.
Playground Link. I added a dummy Promise constructor in there to "polyfill" the lib, but this also reproduces on disk.
The text was updated successfully, but these errors were encountered:
The reason this seems surprising is that for async functions in ES3/ES5, TypeScript takes the identifier in the return type annotation and emits it into the runtime code. It's probably the only case where TS does that.
You can see it in this playground link. StringPromise appears in a value position in the emitted code, and changing or removing the type annotation will change the emitted code.
Search Terms: promise type, not a valid async function return type in es5/es3, alias type
Code
On the latest TS (3.9.2 as of this posting) target set to
es5
, these two code snippets behave differently:Everything works fine here:
Adding this type alias breaks it:
Expected behavior: Adding a type declaration should not affect the behavior of the example. An error should be thrown in both cases or neither.
Actual behavior: Adding a type declaration causes the error
Type 'StringPromise' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value.
Playground Link. I added a dummy Promise constructor in there to "polyfill" the lib, but this also reproduces on disk.
The text was updated successfully, but these errors were encountered: