Skip to content

Always get the apparent type when retrieving a contextual type#3724

Merged
JsonFreeman merged 3 commits into
masterfrom
apparentTypeOfContextualType
Jul 6, 2015
Merged

Always get the apparent type when retrieving a contextual type#3724
JsonFreeman merged 3 commits into
masterfrom
apparentTypeOfContextualType

Conversation

@JsonFreeman
Copy link
Copy Markdown
Contributor

The purpose of contextual typing is to enrich our typing of an expression based on type information from its context. Naturally, this works best when the contextual type is as rich as possible. Looking at getApparentType in the compiler, the type it returns is always at least as rich as the type it takes. So why not make the contextual type even richer by using its apparent type?

This is a language change, and must be reflected in the spec. The difficulty is that apparent type has been removed from the spec. Maybe we should put it back.

Fixes #3708.

@JsonFreeman
Copy link
Copy Markdown
Contributor Author

@ahejlsberg Whenever you have a chance, I'm curious what you think of this change.

@ahejlsberg
Copy link
Copy Markdown
Member

Looks good to me. Particularly makes sense that an inferred type for a type parameter with a constraint that has an index signature also gets an index signature.

JsonFreeman added a commit that referenced this pull request Jul 6, 2015
Always get the apparent type when retrieving a contextual type
@JsonFreeman JsonFreeman merged commit f126767 into master Jul 6, 2015
@JsonFreeman JsonFreeman deleted the apparentTypeOfContextualType branch July 6, 2015 17:18
@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