Fix JSX fragment children type checking in react-jsx mode#62743
Fix JSX fragment children type checking in react-jsx mode#62743
Conversation
…x mode Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
… regular JSX elements Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
tests/baselines/reference/jsxJsxsCjsTransformCustomImportPragma(jsx=react-jsx).errors.txt
Show resolved
Hide resolved
… modes Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
|
@typescript-bot test it |
|
Hey @jakebailey, the results of running the DT tests are ready. Everything looks the same! |
|
@jakebailey Here are the results of running the user tests with tsc comparing There were infrastructure failures potentially unrelated to your change:
Otherwise... Everything looks good! |
|
@jakebailey Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@jakebailey Here are the results of running the top 400 repos with tsc comparing Everything looks good! |
|
@typescript-bot pack this |
|
Starting jobs; this comment will be updated as builds start and complete.
|
|
@typescript-bot pack this |
|
Hey @jakebailey, I've packed this into an installable tgz. You can install it for testing by referencing it in your and then running |
|
I just tested the build and I now get an error if an object is passed as a child of a shorthand fragment when using Running on 560 tsx files, it caught the same two cases than my custom linter rule (opaque type which is a number at runtime) |
|
I asked @weswigham and he said this PR is wrong, unfortunately. |
Fixes #62358
JSX fragments (
<>...</>) inreact-jsx/react-jsxdevmodes were not type-checking children, while explicit<Fragment>worked correctly:Changes
Extended fragment factory resolution to modern JSX modes
getJSXFragmentType: AddedJsxEmit.ReactJSXandJsxEmit.ReactJSXDevtoshouldResolveFactoryReferencecheckJsxEmit.Reactwas checked, causing fragments to returnanyTypein modern modesAdded contextual typing for fragment children
createJsxAttributesTypeFromAttributesProperty: Extract Fragment props type from factory signature and derive children contextual typecheckJsxChildren: Accept optional contextual type parameter, apply to fragment child expressions viacheckExpressionForMutableLocationWithContextualTypeFixed error message for modern JSX modes
getJSXFragmentType: When usingreact-jsx/react-jsxdevmodes, error messages now correctly reference "Fragment" instead of "React"@jsxImportSource preact)Test Coverage
Added
jsxFragmentChildrenCheck.tsxvalidating both syntaxes produce identical type checking.Updated baselines for existing tests now correctly report error 2879 when Fragment factory is missing in react-jsx modes (previously unreported due to
anyTypeearly return), with accurate error messages showing "Fragment" as the expected factory name.Original prompt
<></>syntax, when usingreact-jsxJSX option #62358💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.