Skip to content

Fix weak object relation check#26790

Merged
ahejlsberg merged 6 commits into
masterfrom
fixWeakObjectRelationCheck
Aug 31, 2018
Merged

Fix weak object relation check#26790
ahejlsberg merged 6 commits into
masterfrom
fixWeakObjectRelationCheck

Conversation

@ahejlsberg

@ahejlsberg ahejlsberg commented Aug 30, 2018

Copy link
Copy Markdown
Member

This PR optimizes two code paths:

  • Weak object checks now exclude generic types and therefore never fetch constraints. Previously, for a type variable constrained by a union type we'd end up computing the property set of the union type which can be an expensive operation. Also, we'd do this before checking whether the target is actually a weak type (a relatively cheap check). Now we do it the other way around.
  • Type relationship checks with a tuple on the source side and an array on the target side are now specialized to just check the type of the index signature. This improves performance and error elaborations.

Fixes #26756.

@ahejlsberg

Copy link
Copy Markdown
Member Author

@typescript-bot test this

@typescript-bot

typescript-bot commented Aug 30, 2018

Copy link
Copy Markdown
Contributor

Heya @ahejlsberg, I've started to run the extended test suite on this PR at a35c496. You can monitor the build here. It should now contribute to this PR's status checks.

Type '{}' is not assignable to type 'number'.
Type 'number | {}' is not assignable to type 'number'.
Type '{}' is not assignable to type 'number'.
tests/cases/compiler/tupleTypes.ts(50,1): error TS2322: Type '[number, number]' is not assignable to type '[number, string]'.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I looked for explicit tuple-tuple relations in isRelatedTo and couldn't find it. Can you point me to it?

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.

# Conflicts:
#	tests/baselines/reference/infiniteConstraints.errors.txt
@ahejlsberg ahejlsberg merged commit d293b67 into master Aug 31, 2018
@ahejlsberg ahejlsberg deleted the fixWeakObjectRelationCheck branch August 31, 2018 05:08
@mihailik

Copy link
Copy Markdown
Contributor

Type relationship checks with a tuple on the source side and an array on the target side are now specialized to just check the type of the index signature.

What if the array side is more specific than just array?

interface TupleOfMillion extends Array<number> {
    0: 1000000;
    length: 1;
}

var tmillion: TupleOfMillion, tten: [10];

tmillion = tten; // Type '10' is not assignable to type '1000000'.
tten = tmillion; // Type '1000000' is not assignable to type '10'.

@ahejlsberg

Copy link
Copy Markdown
Member Author

@mihailik The optimization only applies to checks between tuples and Array<T> or ReadonlyArray<T> instantiations. All other types are related structurally as usual.

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.

4 participants