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

Fix #15463: use intersection types to emulate spread in generic react components #15851

Merged
merged 3 commits into from
May 15, 2017

Conversation

mhegazy
Copy link
Contributor

@mhegazy mhegazy commented May 15, 2017

Fixes #15463


const attributeType = createJsxAttributesType(attributes.symbol, attributesTable);

return typeToIntersect ? attributesTable.size ? getIntersectionType([typeToIntersect, attributeType]) : typeToIntersect : attributeType;
Copy link
Member

Choose a reason for hiding this comment

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

what about a flatter form?

typeToIntersect && attributesTable.size ? getIntersectionType([typeToIntersect, attributeType]) : 
typeToIntersect ? typeToIntersect : attributeType 


const attributeType = createJsxAttributesType(attributes.symbol, attributesTable);
return typeToIntersect && attributesTable.size ? getIntersectionType([typeToIntersect, attributeType]) :
typeToIntersect ? typeToIntersect : attributeType;
Copy link
Member

@DanielRosenwasser DanielRosenwasser May 15, 2017

Choose a reason for hiding this comment

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

Consider

if (typeToIntersect) {
    if (attributesTable.size) {
        return getIntersectionType([typeToIntersect, attributeType]);
    }
    return typeToIntersect;
}
return attributeType;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We use the ternary operator quite often. so do not think this is out of line here.

Choose a reason for hiding this comment

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

You would save one condition and make it way easier to read in this case tho

Copy link
Member

@DanielRosenwasser DanielRosenwasser left a comment

Choose a reason for hiding this comment

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

Apart from the simplifying the isValidSpreadType condition, 👍

if (isTypeAny(exprType)) {
hasSpreadAnyType = true;
}
spread = getSpreadType(spread, exprType);
if (!isValidSpreadType(exprType)) {
Copy link
Member

Choose a reason for hiding this comment

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

Invert the condition here and flip them around 😄

@mhegazy mhegazy merged commit d51e467 into master May 15, 2017
@mhegazy mhegazy deleted the Fix15463 branch May 15, 2017 22:46
mhegazy added a commit that referenced this pull request May 15, 2017
… components (#15851)

* Fix #15463: use intersection types to emulate spread in generic react components

* Fix lint errors

* reverse condition
@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.

5 participants