-
Notifications
You must be signed in to change notification settings - Fork 12.3k
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
Nested Promise not automatically unwrapped #59111
Comments
I think this is probably what I'd recommend. I believe @rbuckton did explore something where |
You can't actually have a |
π Search Terms
return type promise union
π Version & Regression Information
This is the behavior in every version I tried, and I reviewed the FAQ for entries about Promise
β― Playground Link
https://www.typescriptlang.org/play/?#code/C4TwDgpgBAyg9gWwgOTgE2gXigZ2AJwEsA7AcygB8oAFfRQnCAHjyLID4BYAKB4EMcIYgGMoAMwCuI4ITjEo CMQz4AwgAtCAGzQAKAJQAuGnQQNm8JKgzsoAbx5QnCiMAn55teowB0inHBaAG4QugBEwBB4Yfo8AL48PJLSsvKKyhD4AIJgYLrCmjrpxpYo6BD69oncCbzcAPT1sOpwEjpQoJAFEMIA1lAARhLAUJl0 DiGPI1OACrg0ADkXmaMLAQkpOyLUAxQxHAjAjiEpMR8A1rQwHAdC1CLrJuLProATADMACwArLHc6RUOTygMyGm0en0-xmzlhAD0APw8IA
π» Code
π Actual behavior
π Expected behavior
No typechecking error
Additional information about the issue
Nodes in React are typed as
type Node = AwaitedNodes | Promise<AwaitedNodes>
. However, the return type of async Components isPromise<Node>
. But TypeScript will not consider this a Component becausePromise<Node>
is not assignable toNode
even though it should be since at runtimePromise<Promise<T>>
will never be observable and always collapse toPromise<T>
.Users can either fix this by using an unwieldy
Promise<Awaited<ReactNode>>
.We can also fix this at the type level by allowing
Node | Promise<Node>
as the return type. Though I suspect this just pushes the issue one Promise-wrapping level away when TypeScript could collapse wrapped Promises automatically.Original issue: vercel/next.js#67365
The text was updated successfully, but these errors were encountered: