Skip to content

Fewer intermediate object literal and array literal types#20380

Merged
ahejlsberg merged 2 commits into
masterfrom
literalContexts
Dec 1, 2017
Merged

Fewer intermediate object literal and array literal types#20380
ahejlsberg merged 2 commits into
masterfrom
literalContexts

Conversation

@ahejlsberg
Copy link
Copy Markdown
Member

@ahejlsberg ahejlsberg commented Dec 1, 2017

With this PR we create fewer intermediate object literal and array literal types. We now preserve literal types for object literal properties and array literal elements only when the corresponding contextual type contains literals of the same primitive type. Previously, we would preserve literal types for properties in object literals and elements in array literals when the corresponding contextual type contained any literal type. This for example meant that we would preserve string literal types for object literal properties and array literal elements if the contextual type contained one (or both) of the literals true or false--in other words, whenever the contextual type contained boolean. Generally this was harmless and only affected types shown in error messages, but on rare occasions (e.g. #20279) it could cause huge numbers of intermediate object literal or array literal types to be created which would subsequently slow down subtype reduction and type relationship checking.

The only changes in to the real world code tests are in error messages.

Fixes #20279.

@ahejlsberg ahejlsberg merged commit bc628bf into master Dec 1, 2017
@ahejlsberg ahejlsberg deleted the literalContexts branch December 1, 2017 22:12
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 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.

2 participants