@types/react
package and had problems.Definitions by:
in index.d.ts
) so they can respond.There was some discussion about the proper type of React.Fragment
in #21146, but while symbol | number
might accurately reflect the internal React type for Fragment
, it prevents React.Fragment
from being used as a TSX element.
<React.Fragment> // error here: React.Fragment does not have any construct or call signatures
<div>Child 1</div>
<div>Child 2</div>
</React.Fragment>
I realize we can render fragments using the <></>
syntax, but the React docs state that this simply de-sugars to <React.Fragment></React.Fragment>
and that this is the only way to add keys to a fragment.
Therefore, I think the type of React.Fragment
should be changed to something closer to React.ComponentType<{}>
, which will give it key
and children
props.
I can open a PR if people agree with this proposal.
Thanks for catching this, @jgoz!
I think the better approach might be for us to fix this on TypeScript's side, rather than changing the type of React.Fragment
to hack around the compiler's behavior.
I'll look into this and see if that is the best approach.
@uniqueiniquity Sounds good. I have a branch ready to go if fixing it in TS is not possible/practical.
@jgoz Go ahead and open the PR. After some discussion here it sounds like you have the right approach for the time being.
Most helpful comment
@uniqueiniquity Sounds good. I have a branch ready to go if fixing it in TS is not possible/practical.