Skip to content

Excess property checking on nested objects doesn't work in JSX as of TS 3.2 #28926

Closed
@pelotom

Description

@pelotom

TypeScript Version: 3.2.2

Search Terms:

excess property jsx

Code

function Foo(props: { x: { foo: number } }) {
  return null;
}

Foo({ x: { foo: 42, bar: 'hello' } }); // <-- correctly has error
<Foo x={{ foo: 42, bar: 'hello' }} />; // <-- incorrectly has no error

Expected behavior:

Both of the last 2 lines should exhibit an excess property error.

Actual behavior:

Only the first line does.

Related Issues:

It's also the case that

React.createElement(Foo, { x: { foo: 42, bar: 'hello' } });

fails to produce the error, however by tweaking the type of createElement in @types/react I'm able to fix that. So #14729 seems related, in that, if the JSX type checking were based on createElement's type, this issue could be fixed by fixing @types/react.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: JSX/TSXRelates to the JSX parser and emitter

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions