Skip to content

Fix weak object relation check #26790

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 6 commits into from
Aug 31, 2018
Merged

Fix weak object relation check #26790

merged 6 commits into from
Aug 31, 2018

Conversation

ahejlsberg
Copy link
Member

@ahejlsberg ahejlsberg commented Aug 30, 2018

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
Member Author

@typescript-bot test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Aug 30, 2018

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 'number | {}' is not assignable to type 'number'.
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
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
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
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
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 join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants