Maaz Zindani

Loading the index…

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

TypeScript says property children is missing in type when you render a React component

ErrorProperty 'children' is missing in type

Short answer

TypeScript is telling you the component's props type lists children as required, and this call site gives none. Either put content between the tags, or make children optional in the type. If strings and numbers fail to type-check, the prop is typed as ReactElement; use ReactNode.

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

Fix it fast

  1. 1Find out which cause you have

    Read the props type of the component named in the error, and look for a children line without a question mark.

    grep -rn "children" src/components/Modal.tsx
  2. 2Match what you see, then jump to its fix

    1. 1Property 'children' is missing in type '{ title: string; }' for a self-closing tag such as <Modal title="x" />.children is declared as required, and the component is used without contentFix
    2. 2A type error appears only when the child is a string, number or fragment.children is typed as ReactElement, but text or numbers are passedFix

What does the error look like?

  • Property 'children' is missing in type

Cause 1 of 2

children is declared as required, and the component is used without content

1Check

In the props interface, children has no question mark, so every use must pass it.

grep -n "children" src/components/Modal.tsx

2Fix

Wrap content in the tags at the call site. If the component works fine without children, mark the property optional with a question mark.

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

3Verify

Run the type check.

npx tsc --noEmit

Confirmed by typescriptlang.org

Did this fix it?

Cause 2 of 2

children is typed as ReactElement, but text or numbers are passed

1Check

ReactElement only accepts JSX elements, not primitives such as strings or numbers.

grep -rn "ReactElement" src/

2Fix

Use ReactNode, the union of everything that can be passed as children.

interface ModalProps {
  title: string;
  children: React.ReactNode;
}

3Verify

Run the type check.

npx tsc --noEmit

Confirmed by react.dev

Did this fix it?

How do I stop it coming back?

  • Type children as React.ReactNode unless you need only JSX elements.
  • Decide for each wrapper component if empty content is allowed, and encode that with or without the question mark.
  • Run tsc --noEmit in CI so type errors do not wait for a release.

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

Web apps

TypeScript rejects MUI Data Grid columns that set a type

A TypeScript error inside a column's renderCell callback

A columns array declared without a type is inferred with type as a plain string, which the Data Grid's column type union does not accept.

2 causes, each with a fix

Next step

Want this handled for good?

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