Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Isolated declarations uses type information to emit return type for async function #58550

Closed
lucacasonato opened this issue May 16, 2024 · 2 comments Β· Fixed by #58628
Closed

Isolated declarations uses type information to emit return type for async function #58550

lucacasonato opened this issue May 16, 2024 · 2 comments Β· Fixed by #58628
Labels
Domain: Isolated Declarations Related to the --isolatedDeclarations compiler flag

Comments

@lucacasonato
Copy link

πŸ”Ž 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

@fatcerberus
Copy link

Without using a type checker, one can not collapse the Promise<Promise<T>> into Promise<T>.

Can't you though? It's impossible to observe nested promises at runtime, so it's always safe to collapse them.

@dragomirtitian
Copy link
Contributor

This is related to #58334. Neither async or generator functions should allow inferred types in isolated declaration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: Isolated Declarations Related to the --isolatedDeclarations compiler flag
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants