The problem is a couple of things. I started by changing children: Array<any> to children: React.ReactNode. You already have a check in there to narrow the type from ReactNode to ReactElement. The trick was 1. using the generic type arguments in isValidElement and 2. using a new variable with a type assignment on it elementChild rather than dealing with and mutating the child argument. EnrichedChildren may need to be updated to match your use case.

interface EnrichedChildren {
  onChange(): void
  selectedValue: string
  name: string
  children?: React.ReactNode
}

enrichRadioElements = (children: React.ReactNode, name: string): any =>
  React.Children.map(children, child => {
    if (!React.isValidElement<EnrichedChildren>(child)) {
      return child
    }

    let elementChild: React.ReactElement<EnrichedChildren> = child
    if (child.props.children) {
      elementChild = React.cloneElement<EnrichedChildren>(elementChild, {
        children: this.enrichRadioElements(elementChild.props.children, name),
      })
    }

    if (elementChild.type === 'Radio') {
      return React.cloneElement(elementChild, {
        onChange: () => {},
        selectedValue: 'value',
        name: name,
      })
    } else {
      return elementChild
    }
  })
Answer from Donovan Hiland on Stack Overflow
🌐
React
react.dev › reference › react › Children
Children – React
Children.map is similar to to transforming arrays with map(). The difference is that the children data structure is considered opaque. This means that even if it’s sometimes an array, you should not assume it’s an array or any other particular data type.
Discussions

Children API is marked as "legacy". What's the .map() alternative?
If you absolutely, seriously, need to update element objects... then yes, React.Children.map() and React.cloneElement() are the right tools to use. I believe the "legacy" bit is that this is considered a sub-optimal usage pattern in the first place and they'd like folks to not use approaches like this if possible. More on reddit.com
🌐 r/reactjs
10
9
January 26, 2023
Type issues when mapping `React.Children.map` and `RX.Component`
Hi, I see some cryptic error that arises when using React.Children.map to wrap the string nodes into a Label component. I can't make sense of why that happens, but subclassing the BaseButton co... More on github.com
🌐 github.com
2
January 29, 2019
Accessing React.children props
I have a component that accepts children of a specific element type and then React.children.maps over it. Inside the component I want to read the props of the elements and map it to something else A basic example (Pick out the title prop of all children and map it to just the string element ... More on forum.rescript-lang.org
🌐 forum.rescript-lang.org
0
0
October 16, 2022
reactjs - React.Children.map Typescript - Stack Overflow
Hi I've been having this issue for few hours and I couldn't figure out the correct type for the child inside the map. I tried using ReactElement but it gives me an error on the first parameter of R... More on stackoverflow.com
🌐 stackoverflow.com
August 13, 2022
🌐
DEV Community
dev.to › devjosemanuel › working-with-react-children-4on7
Working with React children - DEV Community
April 30, 2024 - Achieving in this way that from the point of view of TypeScript right now ComponentA only admits as children those elements that are a ReactElement with the ComponentBProps props. Note: Although from TypeScript's point of view the typing is correct the code editors like VSCode will not do the type checking while we are developing so we have managed to type it right but it is not reflected in the code. What steps do we have to take to go through all the children that a component receives? Well, this is where we have to make use of the map method provided by the React Children object (you can get more information about the React High-Level API here).
🌐
Cristiana's Dev Blog
blog.cristiana.tech › react-children-map-and-cloneelement-using-typescript
React Children Map and cloneElement using TypeScript
March 25, 2021 - {Children.map(children, (child) => { // ... return cloneElement(child, { isActive, onClick }); })} To correctly set the isActive prop and onClick event so that they are based on the activeTab state, we need to get the id props of each Tab.Item. Since we are using TypeScript we must explicitly set the typing ReactElement<PropsWithChildren<TabsItemProps>> which allows us to use the TabsItemProps interface when working with the child props.
🌐
Reddit
reddit.com › r/reactjs › children api is marked as "legacy". what's the .map() alternative?
r/reactjs on Reddit: Children API is marked as "legacy". What's the .map() alternative?
January 26, 2023 -

I'm browsing the latest React (beta) docs, and the Children API is marked as legacy. They have examples for alternatives (which I'm attempting to implement), but aren't showing how to replace the Children.map() function when each child is an unknown component.

Consider a form, where I'm using many different components (<Input />, <Checkbox />, <Button />, etc). I've replaced the cloneElement() function here by returning a new object in the loop with newChild():

const Widget = ({children, name}) => {
    const newChild = (child,i) => {
        const {props} = child
        return {...child, props: {...props, name: `${name}-${i}`}
    }
    
    return (
            <div>
                    {Children.map(children, (child,i) => (
                            <div key={i}>newChild(child)</>
                    ))}
            </div>
    )
}

This simple example updates (or adds) a name prop to every child component. While you can loop over the children prop directly like this:

{children.map((child,i) => (
    <div key={i}>newChild(child)</>
))}

As soon as you pass a single element in, it's treated as an object, and doesn't work with the vanilla js .map() function. Which I thought was the entire reason for Children.map() to exist! Clearly I could use Children.toArray(), but I'd still be using the legacy API.

So, what's the alternative here? The examples they post all conveniently leave out any attempts of actually iterating over the children prop. Are we supposed to stop iterating over it now? Just pass it in and return it? I understand the pitfalls they discuss (eg. the grandchildren aren't rendered), but sometimes there's valid reasons for needing to access each child node. My form-with-lots-of-components example is just one.

I could probably cobble something together that checks if a variable is an object or array, but holy shit, that feels like reinventing a wheel that I'm already using.

🌐
GitHub
github.com › DefinitelyTyped › DefinitelyTyped › issues › 12267
Need React.Children.map() and React.cloneElement() examples · Issue #12267 · DefinitelyTyped/DefinitelyTyped
October 26, 2016 - /> </CheckboxGroup> */ // Child class Checkbox extends React.Component<CheckboxProps, void> { // ... } // Parent class CheckboxGroup extends React.Component<CheckboxGroupProps, void> { // ... render() { const checkboxes = React.Children.map(this.props.children, checkbox => React.cloneElement(checkbox, { name: this.props.name, checked: this.props.checkedValues.includes(checkbox.props.value), onChange: this.handleCheckboxChange.bind(this) }) ); return ( <div> {checkboxes} </div> ); } }
🌐
GitHub
github.com › Microsoft › reactxp › issues › 1009
Type issues when mapping `React.Children.map` and `RX.Component` · Issue #1009 · microsoft/reactxp
January 29, 2019 - import * as React from 'react'; import { Button, Component, Text } from 'reactxp'; export class Label extends Component<{ children?: React.ReactText }> { render() { return <Text>{this.props.children}</Text>; } } class BaseButton extends Component<{ children?: React.ReactNode }> { render() { return ( <Button> {React.Children.map(this.props.children, (child) => ( typeof child === 'string' ?
Author   pronebird
🌐
ReScript Forum
forum.rescript-lang.org › t › accessing-react-children-props › 3852
Accessing React.children props - ReScript Forum
October 16, 2022 - I have a component that accepts children of a specific element type and then React.children.maps over it. Inside the component I want to read the props of the elements and map it to something else A basic example (Pick out the title prop of all children and map it to just the string element ...
Find elsewhere
🌐
Medium
medium.com › @martin_hotell › react-children-composition-patterns-with-typescript-56dfc8923c64
React children composition patterns with TypeScript | by Martin Hochel | Medium
August 16, 2018 - We can tweak our API to leverage both default children and children as an object map, so consumer would be able to use one or another. Let’s have a look at our final Card implementation: ... we’re leveraging union types to define our Component props API. Also we had to change type from ReactNode to ReactChild because ReactNode contains within its definition a mixed type 👉 {} which would narrow our children type to {} instead of being NamedChildrenSlots which remove our strict type checking of our children as object.
🌐
Snyk
snyk.io › advisor › react › functions › react.children
How to use the react.Children function in react | Snyk
const getChildChecked = (children: ReactNode) =&gt; { const checkedValue: Array = []; React.Children.map(children, (element: ReactNode) =&gt; { if (React.isValidElement(element) &amp;&amp; element.props &amp;&amp; element.props.checked) { checkedValue.push(element.props.value); } }); return checkedValue; };
🌐
Smashing Magazine
smashingmagazine.com › 2021 › 08 › react-children-iteration-methods
React Children And Iteration Methods — Smashing Magazine
August 4, 2021 - Because we have access to index inside the iterator function (second argument of callback function of React.Children.map) we are able to detect if the child is last-child or not.
🌐
Carl Rippon
carlrippon.com › react-children-with-typescript
React Children with TypeScript
September 23, 2020 - The React children prop allows components to be composed together and is a key concept for building reusable components. Visually, we can think of it as a hole in the component where the consumer controls what is rendered.
🌐
LogRocket
blog.logrocket.com › home › how to type react children correctly in typescript
How to type React children correctly in TypeScript - LogRocket Blog
December 19, 2025 - Learn best practices for typing React children in TypeScript, including ReactNode, PropsWithChildren, ComponentProps, and why React.FC is no longer recommended.
🌐
Medium
medium.com › @devUnemployed › react-children-props-with-typescript-9d369343e18a
React children props with TypeScript | by Jam | Medium
January 1, 2024 - interface BasicPageProps { title: string; children: ReactNode | ReactNode[]; } export const BasicPage = ({ title, children }: BasicPageProps) => { ...
🌐
Today I Learned
til.hashrocket.com › posts › yb1ee3dhxp-mapping-over-one-or-many-children-in-react
Mapping Over One Or Many Children In React - Today I Learned
June 16, 2020 - const ParentWithClick = ({ children }) => { return ( <React.Fragment> {React.Children.map(children || null, (child, i) => { return <child.type {...child.props} key={i} onClick={handleClick} />; })} </React.Fragment> ); };
🌐
Steve Kinney
stevekinney.com › courses › react with typescript › typing children and when to use reactnode
Typing Children and When to Use ReactNode | React with TypeScript | Steve Kinney
4 weeks ago - Here’s how to use them with proper TypeScript typing: ... import { ReactNode, cloneElement, isValidElement } from 'react'; interface WrapperProps { children: ReactNode; } function AddClassToChildren({ children }: WrapperProps) { return ( <div> {React.Children.map(children, (child, index) => { // Type guard to ensure we have a valid React element if (isValidElement(child)) { return cloneElement(child, { className: `${child.props.className || ''} wrapped-${index}`.trim(), }); } // Return non-element children (strings, numbers) unchanged return child; })} </div> ); }
🌐
Pluralsight
pluralsight.com › tech insights & how-to guides › tech guides & tutorials
How to Iterate Through a Component's Children in React Typescript | Pluralsight
August 18, 2020 - import React from "react"; import UserInterface from "User.interface.tsx"; interface AppProps { children: React.ReactElement<UserInterface>[]; } class App extends React.Component<AppProps, {}> { render() { return this.props.children.map( (child: React.ReactElement<UserInterface>) => ( <div>{child.props.name}</div> ) ); } } TypeScript is an excellent utility that can be used to create a type-checked codebase.