fix: do not use JSX.ElementChildrenAttribute under jsx: react-jsx or jsx: react-jsxdev - #60880
Conversation
There was a problem hiding this comment.
it might be good to add a test case that defines ElementChildrenAttribute as something different than children to verify that it's ignored in favor of "hard-coded" children
There was a problem hiding this comment.
Indeed! Added a test case.
…react-jsx and react-jsxdev
|
TypeScript Bot (@typescript-bot) test it |
|
Jake Bailey (@jakebailey) Here are the results of running the user tests with tsc comparing Everything looks good! |
|
Hey Jake Bailey (@jakebailey), the results of running the DT tests are ready. Everything looks the same! |
|
Jake Bailey (@jakebailey) Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Jake Bailey (@jakebailey) Here are the results of running the top 400 repos with tsc comparing Everything looks good! |
Happy Holidays! Fixes #60572
🖼️ Background
Under
jsx: react-jsxorjsx: react-jsxdev, the name of the prop for JSX children is alwayschildren. The jsx transformer properly implements this:TypeScript/src/compiler/transformers/jsx.ts
Line 308 in 56a0825
However, the type checker didin't take this into consideration. Instead, it used
JSX.ElementChildrenAttributeto determine the name of prop. If type definition lacks this interface, undesirable compiler errors are emitted (like the one mentioned in the linked issue).It is of note that, I believe, no practical type definition for JSX libraries ever provided such definition that would lead to errors like those.
That said, I think the current behavior is still a bit harmful to those who want to learn how to write type definitions for JSX libraries, so proposing a fix.
🦾 Solution
This PR fixes the
getJsxElementChildrenPropertyNamefunction so thatchildrenis hard-coded under thesejsxmodes.🌵 Current Behavior
code:
Errors:
✨ New Behavior
(No error)