Skip to content

Bug: Valid programs with JSX fail to typecheck when JSX is de-sugaredΒ #46988

@jameshfisher

Description

@jameshfisher

πŸ”Ž Search Terms

jsx children

πŸ•— 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

import React from 'react'

// This example comes from https://github.com/vercel/next.js/blob/5544adc481f8821567e947a6e6d51d9d68ebd367/packages/next/shared/lib/head.tsx#L172
declare function Head({ children }: {
    children: React.ReactNode;
}): JSX.Element;

// This typechecks
const PageWithJSX = () => (
    <Head>
        <title>Hello</title>
    </Head>
)

// This does not typecheck
const PageWithoutJSX = () => React.createElement(Head, {},
    React.createElement('title', {}, 'Hello'),
)

πŸ™ Actual behavior

The non-JSX code gives the type error:

No overload matches this call.
  The last overload gave the following error.
    Argument of type '{}' is not assignable to parameter of type 'Attributes & { children: ReactNode; }'.
      Property 'children' is missing in type '{}' but required in type '{ children: ReactNode; }'.(2769)
input.tsx(5, 5): 'children' is declared here.

πŸ™‚ Expected behavior

No type error should be given, because it's just the same as the code that does type-check, only without JSX.

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