Skip to content

Resolve the context sensitive expression containers before resolving node#1362

Merged
sheetalkamat merged 3 commits into
masterfrom
contextSensitiveExpressions
Dec 4, 2014
Merged

Resolve the context sensitive expression containers before resolving node#1362
sheetalkamat merged 3 commits into
masterfrom
contextSensitiveExpressions

Conversation

@sheetalkamat
Copy link
Copy Markdown
Member

When trying to get type/symbol information of the location, make sure that its context sensitive expression containers are resolved in top down manner to avoid incorrectly making something any because of recursive recursion that can occur during resolution.

Fixes #1165

Comment thread src/compiler/checker.ts Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why getNarrowedType here, but not above?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I will add inline comment too.. but this is because getTypeOfNode by default does narrowing and gets it correctly. But if you just gettype of symbol it wouldn't be narrowed. It needs node at which you are trying to get type of symbol so that it can decide if it can decide when and how to narrow the type.

eg. consider this:
function foo(a: string | number) {
if (typeof a === "string") {
a/**/
}
}

The symbol of a is a parameter symbol. and if you can getTypeOfSymbol then it would be string | number because there is no node information specified

But if you tell I want type of a at the /**/ location it can decide to narrow it to "string"

@mhegazy
Copy link
Copy Markdown
Contributor

mhegazy commented Dec 4, 2014

👍

sheetalkamat added a commit that referenced this pull request Dec 4, 2014
Resolve the context sensitive expression containers before resolving node
@sheetalkamat sheetalkamat merged commit e3320c2 into master Dec 4, 2014
@sheetalkamat sheetalkamat deleted the contextSensitiveExpressions branch December 4, 2014 21:02
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 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.

Type detection fails in this circumstance

3 participants