Skip to content

Add spread syntax to JsxExpression #11591

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 4 commits into from
Dec 22, 2016
Merged

Conversation

sandersn
Copy link
Member

@sandersn sandersn commented Oct 13, 2016

Fixes #9495

This allows you to specify that a JsxExpression should be a list that will be flattened by the JSX consumer.

Thanks @yuit for your 30-minute crash course on how the compiler handles JSX!

This allows you to specify that a JsxExpression should be a list that
will be flattened by the JSX consumer.
@sandersn
Copy link
Member Author

@yuit @RyanCavanaugh can one of you take a look at this?

@@ -10904,7 +10904,11 @@ namespace ts {

function checkJsxExpression(node: JsxExpression) {
if (node.expression) {
return checkExpression(node.expression);
const type = checkExpression(node.expression);
if (node.dotDotDotToken && !isArrayType(type)) {
Copy link
Member

Choose a reason for hiding this comment

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

Check for type being any

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@RyanCavanaugh
Copy link
Member

Needs tests for jsx: react emit

@sandersn
Copy link
Member Author

tsxSpreadChildrenInvalidType.tsx tests jsx: react emit (even though it has the incorrect type).
Note that react emit doesn't change because React.createElement handles both array and non-array inputs.

@sandersn
Copy link
Member Author

@RyanCavanaugh I just noticed that I forgot about this. Is it good to go in?

@mhegazy
Copy link
Contributor

mhegazy commented Dec 22, 2016

@sandersn can you please refresh this PR.

@sandersn sandersn merged commit 21c04bd into master Dec 22, 2016
@sandersn sandersn deleted the spread-jsx-expression-children branch December 22, 2016 22:24
return checkExpression(node.expression);
const type = checkExpression(node.expression);
if (node.dotDotDotToken && type !== anyType && !isArrayType(type)) {
error(node, Diagnostics.JSX_spread_child_must_be_an_array_type, node.toString(), typeToString(type));
Copy link
Member

Choose a reason for hiding this comment

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

These arguments are unused :(

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 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