Skip to content

JSX Spread Type Safety #16725

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

Closed
ccorcos opened this issue Jun 23, 2017 · 6 comments
Closed

JSX Spread Type Safety #16725

ccorcos opened this issue Jun 23, 2017 · 6 comments
Labels
Duplicate An existing issue was already created

Comments

@ccorcos
Copy link

ccorcos commented Jun 23, 2017

TypeScript Version: 2.2.2, 2.3.4

Code

class Test extends React.Component<{ x: number }, {}> {}

<Test /> // Error 👍
<Test x={1} /> // No Error 👍
<Text y={1} /> // Error 👍
<Test x={1} y={2} /> // Error 👍
<Test {...{ x: 1 }} /> // No Error 👍
<Test {...{ y: 2 }} /> // Error 👍
<Test {...{ x: 1, y: 2 }} /> // No Error 👎

Expected behavior:

I would expect extra props passed in an object spread to throw a type error. Otherwise I don't know if I'm passing props that are lost in translation.

Actual behavior:

I don't get a type error.

@devdoomari
Copy link

but what about codes that actually make use of that property?
eg.

const someProps = Object.assign({}, defaultProps, data1, data2);
...
<Test {...someProps} />

?

@mohsen1
Copy link
Contributor

mohsen1 commented Jun 24, 2017

@sandersn #16530 didn't fix TSX spread?

@sandersn
Copy link
Member

It's in release 2.4 @ccorcos can you try typescript@next or typescript@rc ?

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jun 26, 2017
@ccorcos
Copy link
Author

ccorcos commented Jun 26, 2017

I'll try it out and get back you -- thanks for the help!

@mohsen1
Copy link
Contributor

mohsen1 commented Jun 26, 2017

I saw this working in 2.4 for JSX this weekend.

@mhegazy
Copy link
Contributor

mhegazy commented Aug 17, 2017

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@mhegazy mhegazy closed this as completed Aug 17, 2017
@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
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

6 participants