Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

TypeScript rejects the content you put between a React component's tags

ErrorProperty 'children' does not exist on type 'IntrinsicAttributes & Props'

Short answer

Since the React 18 typings, a component no longer gets a children prop for free from React.FC or React.Component. If your props type does not list children, TypeScript refuses content between the tags. Add children?: React.ReactNode to the props type, or stop passing children to a component that does not render them.

  • Applies to TypeScript 5, React 18
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find out which React typings are installed, then list every place the compiler complains. If @types/react is 18 or later, the React 18 typings change applies and the causes below are the places to look.

    npm ls @types/react
    npx tsc --noEmit
  2. 2Match what you see, then jump to its fix

    1. 1The error points at a JSX tag such as <Panel>...</Panel>, and Panel is a function whose props type has no children lineA function component's props type never mentions childrenFix
    2. 2The component is written as class X extends React.Component<Props> and renders this.props.childrenA class component relied on the implicit children of React.ComponentFix
    3. 3A component from a UI package, or from your own code, that renders its text from another prop such as label or textThe component does not take children at allFix

What does the error look like?

  • Property 'children' does not exist on type 'IntrinsicAttributes & Props'
  • The same code compiled before @types/react or React was upgraded, and no source line changed

Cause 1 of 3

A function component's props type never mentions children

1Check

Typings older than 18 added children to every component typed through React.FunctionComponent (React.FC). The new ones do not, so a component that used the free prop must now say so itself. Search for components typed that way.

grep -rnE 'React\.FC|FunctionComponent' src/

2Fix

List children in the props type. Use React.ReactNode so text, numbers, elements and arrays are all accepted; drop the question mark if the component is useless without content.

interface PanelProps {
  title: string;
  children?: React.ReactNode;
}

function Panel({ title, children }: PanelProps) {
  return (
    <section>
      <h2>{title}</h2>
      {children}
    </section>
  );
}

3Verify

Run the compiler again and expect no output for that tag.

npx tsc --noEmit

Confirmed by react.dev

Did this fix it?

Cause 2 of 3

A class component relied on the implicit children of React.Component

1Check

The typings change covered class components as well as function components: anything that used the implicit declaration now has to declare children. Look for classes that read this.props.children.

grep -rnE 'this\.props\.children' src/

2Fix

Add children to the interface you pass as the first type argument.

interface CardProps {
  children?: React.ReactNode;
}

class Card extends React.Component<CardProps> {
  render() {
    return <div className="card">{this.props.children}</div>;
  }
}

3Verify

The class tag type-checks with content between its tags.

npx tsc --noEmit

Confirmed by github.com

Did this fix it?

Cause 3 of 3

The component does not take children at all

1Check

TypeScript turns whatever sits between the tags into the children property of the props object. If the props type has no such property, there is nowhere to put it. Read the component's props type and see which prop carries the content.

grep -n 'children' node_modules/my-ui-lib/dist/index.d.ts

2Fix

Pass the content through the prop the component does have, instead of between the tags.

// rejected: Badge declares label, not children
<Badge>New</Badge>

// accepted
<Badge label="New" />

3Verify

The compiler accepts the usage, and the badge shows the text on screen.

npx tsc --noEmit

Confirmed by typescriptlang.org

Did this fix it?

How do I stop it coming back?

  • Declare children in the props of every component that renders it, and type it as React.ReactNode unless you really want exactly one element.
  • Keep @types/react and @types/react-dom updated together with React; the React 18 upgrade guide asks for both.
  • Run tsc --noEmit in your build pipeline so a typings upgrade fails there with the full list of broken components.
  • Before a big React upgrade, read the TypeScript section of its upgrade guide, which links the types-react-codemod migration tool; the React 19 guide links it again for its own type changes.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.