Skip to content
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

Perform excess property checking on intersection and union members #30853

Conversation

weswigham
Copy link
Member

Fixes #28616
Fixes #18075
Fixes #13813

cc @JasonGore - I believe this enhances excess property checking to the point where it should cover all the faculties JSX tags in 2.8 had.

@weswigham
Copy link
Member Author

@typescript-bot test this & @typescript-bot run dt & @typescript-bot user test this

What a command.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 11, 2019

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 11, 2019

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 11, 2019

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

@RyanCavanaugh
Copy link
Member

RWC Summary

  • One improved error message (we previously failed to elaborate)
  • One change in type readout (differently-ordered union; benign)
  • A somewhat surprising break in VS Code that seems unrelated?

Extracted:

interface IStringDictionary<V> {
	[name: string]: V;
}
interface INumberDictionary<V> {
	[idx: number]: V;
}

declare function forEach<T>(from: IStringDictionary<T> | INumberDictionary<T>, callback: (entry: { key: any; value: T; }, remove: () => void) => any);

let count = 0;
collections.forEach({ toString: 123 }, () => count++);
                      ~~~~~~~~
!!! error TS2322: Type 'number' is not assignable to type '() => string'.

I don't really disagree with the error but it'd be good to understand why it popped up

@weswigham
Copy link
Member Author

weswigham commented Apr 11, 2019

Yeah, I saw that and was equally confused. Definitely need to look at 1. what that code's even meant to be doing and 2. why does this affect it?

DT results also seem noisy (there's failures on latest master), but there's around 16 new changes there - they mostly look like new excess prop errors (example: cytoscape now errors on a content property in its tests - the identifier content doesn't even appear in the library's types anywhere), but it's worth inspecting more closely.

result = typeRelatedToEachType(getRegularTypeOfObjectLiteral(source), target as IntersectionType, reportErrors);
if (result && isPerformingExcessPropertyChecks) {
// Validate against excess props using the original `source`
if (!propertiesRelatedTo(source, target, reportErrors)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the propertiesRelatedTo check more expensive than the typeRelatedToEachType check? Does it make sense to do the checks in the other order?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think usually, yeah - we typically consider structural decomposition more expensive than algebraic comparison.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah ok, fair enough. I thought that typeRelatedToEachType would end up calling into propertiesRelatedTo for each union component anyway via isRelatedTo.

Copy link
Member Author

Choose a reason for hiding this comment

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

It can; but that's the last kind of comparison we make - any other comparison succeeding avoids it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That makes sense. Ty!

@weswigham
Copy link
Member Author

@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 11, 2019

Heya @weswigham, I've started to run the tarball bundle task on this PR at f87ba3f. You can monitor the build here. It should now contribute to this PR's status checks.

@Jessidhia
Copy link

That error message looks suspiciously like what you'd get from an extends Object constraint; or otherwise something that expects your object to conform to the Object.prototype.

@weswigham
Copy link
Member Author

Wew, so having finally finished going thru them, every related DT break seemed like a really good change where we were catching a bug in either the test code or the type definitions. I've opened:
DefinitelyTyped/DefinitelyTyped#34705
DefinitelyTyped/DefinitelyTyped#34704
DefinitelyTyped/DefinitelyTyped#34702
DefinitelyTyped/DefinitelyTyped#34701
DefinitelyTyped/DefinitelyTyped#34698
DefinitelyTyped/DefinitelyTyped#34697
DefinitelyTyped/DefinitelyTyped#34696
DefinitelyTyped/DefinitelyTyped#34681
DefinitelyTyped/DefinitelyTyped#34680
DefinitelyTyped/DefinitelyTyped#34679
DefinitelyTyped/DefinitelyTyped#34677
DefinitelyTyped/DefinitelyTyped#34676
DefinitelyTyped/DefinitelyTyped#34700
DefinitelyTyped/DefinitelyTyped#34699
DefinitelyTyped/DefinitelyTyped#34671
and
knockout/knockout#2475

to fix up those breaks on DT - all of them are corrections or improvements to the tests or declarations for a package.

@weswigham
Copy link
Member Author

I don't really disagree with the error but it'd be good to understand why it popped up

Fix't. The type.propertyCache is, unfortunately, polluted with any members we find on the apparent type of a thing, rather than just being direct members, so I can't use it verbatim (as apparent type members don't usually come into play during assignability checking). Not really a big deal since we were still iterating over the type to initialize all the properties anyway; it just means I can't sneakily avoid allocating a symbol table to collect unique entries by leveraging an existing one.

HasLiteralType = 1 << 7, // Synthetic property with at least one literal type in constituents
ContainsPublic = 1 << 8, // Synthetic property with public constituent(s)
ContainsProtected = 1 << 9, // Synthetic property with protected constituent(s)
ContainsPrivate = 1 << 10, // Synthetic property with private constituent(s)
Copy link
Member

Choose a reason for hiding this comment

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

Off-by-one whitespace 😲

@weswigham
Copy link
Member Author

Before I merge: @typescript-bot test this & @typescript-bot run dt & @typescript-bot user test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 17, 2019

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 17, 2019

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 17, 2019

Heya @weswigham, I've started to run the parallelized Definitely Typed test suite on this PR at f54e5ab. You can monitor the build here. It should now contribute to this PR's status checks.

weswigham added a commit to DefinitelyTyped/DefinitelyTyped that referenced this pull request Apr 17, 2019
Found while working on microsoft/TypeScript#30853 - asd is never augmented into HandlerDecorations in any tests, so it's excess and, with the mentioned PR, an error.

#34701 but again for the new location of the types, pretty much.
@weswigham
Copy link
Member Author

Only DT failure is a new copy of a hapi test I already fixed once (they got copied to a namespace while I was working, apparently); opened DefinitelyTyped/DefinitelyTyped#34790, RWC changes are the remaining error message changes; so everything looks good. Going to merge~

@weswigham weswigham merged commit 169e485 into microsoft:master Apr 17, 2019
@weswigham weswigham deleted the fix-intersection-target-excess-props-checks branch April 17, 2019 04:58
weswigham added a commit to DefinitelyTyped/DefinitelyTyped that referenced this pull request Apr 17, 2019
Found while working on microsoft/TypeScript#30853 - asd is never augmented into HandlerDecorations in any tests, so it's excess and, with the mentioned PR, an error.

#34701 but again for the new location of the types, pretty much.
alesn pushed a commit to alesn/DefinitelyTyped that referenced this pull request Apr 23, 2019
Found while working on microsoft/TypeScript#30853 - asd is never augmented into HandlerDecorations in any tests, so it's excess and, with the mentioned PR, an error.

DefinitelyTyped#34701 but again for the new location of the types, pretty much.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants