Isolated declarations uses type information to emit return type for async function
🔎 Search Terms
- isolated declarations
- return type
- async function
🕗 Version & Regression Information
5.5.0-dev.20240514
⏯ Playground Link
https://www.typescriptlang.org/play/?target=99&isolatedDeclarations=true&ts=5.5.0-dev.20240514#code/KYDwDg9gTgLgBAQwM4E8B2BjOAzArpmASwjThAAoBKOAbwCg44pgZcpSaBfRJOABSgQAtoSTAAPADcIhACYA+OpyA
💻 Code
export async function x() {
return {} as Promise<void>
}
🙁 Actual behavior
TypeScript emits the following:
export declare function x(): Promise<void>;
🙂 Expected behavior
Error, or emit:
export declare function x(): Promise<Promise<void>>;
Without using a type checker, one can not collapse the Promise<Promise<T>> into Promise<T>. This means that with ID, a tool could not always emit identical token lists to TSC, even when ID is enabled.
Additional information about the issue
cc @dragomirtitian
Without using a type checker, one can not collapse the
Promise<Promise<T>>intoPromise<T>.
Can't you though? It's impossible to observe nested promises at runtime, so it's always safe to collapse them.
This is related to #58334. Neither async or generator functions should allow inferred types in isolated declaration