Skip to content

Only get the apparent type of a contextual type when needed #5607

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 7 commits into from
Nov 11, 2015

Conversation

DanielRosenwasser
Copy link
Member

Fixes #5598.

Background

For quite a while, it was the case that when seeking the contextual type of a value, we would always get its apparent type afterwards. This was usually the behavior desired - otherwise, you'd typically run into problems with things like object literals and index signatures.

During recent work on string literal types, this turned out to be undesirable because the widened type of a string literal type is the global String type. This was effectively useless because we needed to check whether the contextual type was string literal type or a union with a string literal type, so we separated out the concept of grabbing an expression's contextual type (with getContextualType) with grabbing the apparent type of that contextual type (getApparentTypeOfContextualType).

One thing missed in that change was that internally, getContextualType was calling getApparentTypeOfContextualType unnecessarily. This means that if you had a parenthesized string literal, it could never be contextually typed by a string literal type - it would instead get contextually typed by the global string type.

The reason the apparent type was necessary in some places is that when "digging in" to a type, it's necessary to get the apparent type to recognize its available members, the shape of its type constraint, etc.; however, the apparent type is not needed in simple cases where we simply propagate the type back.

@RyanCavanaugh
Copy link
Member

👍

DanielRosenwasser added a commit that referenced this pull request Nov 11, 2015
Only get the apparent type of a contextual type when needed
@DanielRosenwasser DanielRosenwasser merged commit 9c1796f into master Nov 11, 2015
@DanielRosenwasser DanielRosenwasser deleted the fixTypeApparentization branch November 11, 2015 18:27
@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.

3 participants