Skip to content

Fix type check for async function with alias return type. #5429

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

Merged
merged 2 commits into from
Oct 28, 2015

Conversation

rbuckton
Copy link
Contributor

Switched to resolvedSymbol from NodeLinks instead of mergedSymbol from the type. When the return type is a type alias, we eagerly resolve the actual type. This resuls in a false positive for a type that exists as a value.

There is a minor change to the error reporting here, as I want to report the error using the name of the alias used in the return type, not the name of the resolved type of the alias. This is so you don't see an error like "Type 'Promise' is not a valid async function return type" when you use an alias for Promise. This has the side effect of not including the type arguments in the error message, but I think that's acceptable.

Fixes #5333.

@@ -28,7 +28,7 @@ tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration1
!!! error TS1055: Type 'number' is not a valid async function return type.
async function fn5(): PromiseLike<void> { } // error
~~~
!!! error TS1055: Type 'PromiseLike<void>' is not a valid async function return type.
!!! error TS1055: Type 'PromiseLike' is not a valid async function return type.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the alias case that the change is meant to fix?

@sandersn
Copy link
Member

OK, thanks for the the in-person explanation -- getMergedSymbol(promiseType.symbol) resolves the type and gets the name, getNodeLinks(node.type).resolvedSymbol doesn't resolve the type and gets the name. Which gives the alias name as desired.

@sandersn
Copy link
Member

👍

rbuckton added a commit that referenced this pull request Oct 28, 2015
Fix type check for async function with alias return type.
@rbuckton rbuckton merged commit 9201ba2 into master Oct 28, 2015
@rbuckton rbuckton deleted the fixAsyncTypeAlias branch October 28, 2015 21:17
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid code generated when namespaced type is used as return type for async function
3 participants