Skip to content

TypeScript ignores type of JSX spread props if the JSX tag is non-empty #44782

Closed
@bluenote10

Description

@bluenote10

Bug Report

🔎 Search Terms

jsx empty

Possibly related issues:

Related SO question: Why does TypeScript ignore the type of JSX spread props if the JSX tag is not empty?

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about JSX.

⏯ Playground Link

Playground link with relevant code

💻 Code

This assumes JSX: React

const badProps = {
  badProp: "foo",
};

// This doesn't compile; as expected.
function Test1() {
  return <div {...badProps} />;
}

// This does compile; not expected.
function Test2() {
  return <div {...badProps}> </div>;
}

🙁 Actual behavior

The expression in Test2 compiles without error.

🙂 Expected behavior

Type checks should apply to both empty and non-empty usages, and result in the same compilation 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