TypeScript: Error: TS1055: Type 'Promise' is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value.
I already read this https://github.com/Microsoft/TypeScript/issues/12776#issuecomment-265885846 but is not possible to fix. Or I can’t understand how has even been solved.
Is fixed by adding const AsyncBool = Promise; but is not possible in my case scenario. Also where can I read about this strange syntax. A type and a const with the same name?! Looks strange and confusing.
async function foo(): Promise<boolean> {
return Promise.resolve(true);
}
type AsyncBool = Promise<boolean>;
const AsyncBool = Promise;
async function bar(): AsyncBool {
return Promise.resolve(true);
}
Code
interface O {
o: Promise<number>,
}
const myFn = async ():O["o"] => {
}
Expected behavior:
No error.
Actual behavior:
Error: TS1055: Type ‘Promise<number>’ is not a valid async function return type in ES5/ES3 because it does not refer to a Promise-compatible constructor value.
Playground Link:
(by the way don’t search “ts playground” on google. TS team needs to invest in some SEO I guess.)
Related Issues: https://github.com/Microsoft/TypeScript/issues/12776
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 33
- Comments: 39 (5 by maintainers)
This issue has been marked as ‘Question’ and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you’re still waiting on a response, questions are usually better suited to stackoverflow.
I’m having the same issue with
axios’AxiosPromisetyping (see: https://github.com/axios/axios/blob/master/index.d.ts#L87 )I’m getting:
As you can see in the provided link, it’s just:
Here’s the code I use:
If I copy the type, it works as expected:
Who should we tag to reopen this, I found only one name?
Hello, @RyanCavanaugh, this is not a question, but clearly a bug that needs fixing. If it’s not a duplicate, please change the issue type and re-open.
Regards
It seems to me that if this expression is valid typescript:
(and it is)… then the following expression should also be valid typescript:
the nature of the implementation of choosing a promise-compatible constructor to use during desugaring seems to be, or at least seems like it should be, an independent concern that doesn’t bear on the case where the return type aliases directly and inarguably to the already acceptable Promise type.
Said differently, In cases where the literal word
Promiseis acceptable, why shouldn’t any other type alias which resolves deterministically to it and only it be also acceptable?Forgive me if I am overlooking something. 😃
With arrow functions it might work by moving the type declaration to the
constobject.Don’t use
"target": "es5"intsconfig.json, use something likeesnextshould work!“target”: “esnext”,
For me, this issue arose with a conditional type. I changed
to
In other words, wrapping the whole conditional in a promise worked when splitting the promises inside the conditional didn’t.
@RyanCavanaugh ping
The same with built-in
ReturnTypehelper:https://www.typescriptlang.org/play/index.html#src=async function fooBar()%3A Promise<void> { } async function barBaz()%3A ReturnType<typeof fooBar> { }