Maaz Zindani

Loading the index…

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

TypeScript 7031 on a destructured children prop in React

ErrorBinding element 'children' implicitly has an 'any' type.ts(7031)

Short answer

With noImplicitAny on, TypeScript refuses to guess a type it cannot infer. A component written as ({ children }) has no type for its props object, so every destructured name becomes an implicit any. Give the props an interface that declares children as React.ReactNode, and keep strict on.

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

Fix it fast

  1. 1Find out which cause you have

    Check whether strict or noImplicitAny is on. If it is, the error is working as designed and the fix is a type on the props, not a config change.

    npx tsc --showConfig | grep -E 'strict|noImplicitAny'
  2. 2Match what you see, then jump to its fix

    1. 1The line is function Layout({ children }) { ... } with nothing after the closing braceThe props object has no type annotationFix
    2. 2The component is built inside a helper, higher-order function or callback, for example withAuth(({ children }) => ...)A wrapper function gives the component no contextual typeFix

What does the error look like?

  • Binding element 'children' implicitly has an 'any' type.ts(7031)

Cause 1 of 2

The props object has no type annotation

1Check

TypeScript falls back to any when it cannot infer a type and there is no annotation. With noImplicitAny enabled, it reports an error at that point.

grep -rn '({ *children' src/

2Fix

Declare the props and type children as React.ReactNode, which accepts anything React can render.

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

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

3Verify

Run the type check. Error 7031 is gone and a wrong prop type is now reported.

npx tsc --noEmit

Confirmed by react.dev

Did this fix it?

Cause 2 of 2

A wrapper function gives the component no contextual type

1Check

In that spot TypeScript has nothing to infer from, so the parameter is untyped. The same rule applies: no inferred type and no annotation means implicit any.

grep -rn 'withAuth\|=> *{$' src/ | head

2Fix

Annotate the parameter at the place it is written, with the same props type.

type Props = { children: React.ReactNode };

const Guarded = ({ children }: Props) => <main>{children}</main>;

3Verify

Run the type check again.

npx tsc --noEmit

Confirmed by typescriptlang.org

Did this fix it?

How do I stop it coming back?

  • Keep strict on in tsconfig.json and type props at the component, not later.
  • Reuse one shared props type for layout components that only take children.

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.