Skip to content

JSX Spread Type Safety #16725

Closed
Closed
@ccorcos

Description

@ccorcos

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions