Try this, importing ReactChildren from react.

I wish i could explain this better, but i know typescript is expecting a JSX/TSX element, so we could use ReactElement for the return type.

For a better explanation on the children type

https://stackoverflow.com/a/58123882/7174241

import React, { ReactChildren, ReactElement, ReactNode } from "react";

interface RequireType {
  children: ReactChildren | ReactNode | ReactElement;
  required_permission: string;
}

const RequirePermission = ({ children, required_permission }: RequireType):ReactElement => {
  const user = useContext(AuthContext);

  let hasPermission = false;
  if (user.state == AuthState.Authorized) {
    user.user?.realm_access?.roles.forEach((role) => {
      if (permissions[role].includes(required_permission)) {
        hasPermission = true;
      }
    });
  }

 return <>{hasPermission ? children : null}</>

};

export default RequirePermission;
Answer from BARNOWL on Stack Overflow
🌐
Reddit
reddit.com › r/reactjs › how to create typescript generic for a wrapper component
r/reactjs on Reddit: How to create Typescript Generic for a wrapper component
July 13, 2021 -

Hi,

code example

I am starting with the TS in React and I have no idea how to rewrite my wrapper component to TS.

I have multiple inputs components (MyInput and MyTextArea in the example) and each have a custom props. I want to create a wrapper which can take the input as a prop but also can reuse types from the input. e.g.:

this is how it looks like without the wrapper

<MyInput
    customProp1="regular input"  
    value={value}    
    onChange={e => setValue(e.target.value)} 
/>

and this is how it should looks like with the wrapper

<MyWrapper
    input={MyInput}
    customProp1="wrapped input"
    value={value2}
    onChange={e => setValue2(e.target.value)}
/>

Currently in my example the MyWrapper has the "any" type. How to replace the "any" with a "MyInput"/"MyTextArea" ts types? In this example MyWrapper need the access to "value" and "onChange" props so I can not pass the input as a child.

Discussions

reactjs - How to best type a TypeScript collection of React wrappers - Stack Overflow
I'm able to write a simple ... will enforce that each wrapper component gets its correct props type as well. Here's some code to illustrate the problem. Essentially, my question is how to define WrapperSet. import * as React from "react"; export const Container: React.FC ... More on stackoverflow.com
🌐 stackoverflow.com
Can't specify correct types for a wrapper component around `Button`, in TypeScript
I've written a wrapper component for Button. Like this: import { Button } from 'react-bootstrap'; function WrapperButton(props) { const { children } = props; return {children}; } Since I'm using this in TypeScript, I'm trying to add types to props. More on github.com
🌐 github.com
5
February 28, 2020
reactjs - Typescript + React: Typing a functional wrapper component that extends a given class component - Stack Overflow
I have a functional component that wraps a class component and passes all but one prop to it: import React, { Component, ComponentType } from 'react' import Layout from './components/LayoutCompone... More on stackoverflow.com
🌐 stackoverflow.com
December 1, 2019
how to create a wrapper that changes the props for the component in react
I m trying to do something with react components for the first time and need your help, I want to wrap a component inside another one dynamically and changing its props. for example, let's say I have More on stackoverflow.com
🌐 stackoverflow.com
🌐
Max Rozen
maxrozen.com › implement-higher-order-component-react-typescript
How to implement a Higher-order component in React with TypeScript - Max Rozen
import React, { useState } from 'react'; // First we need to add a type to let us extend the incoming component. type ExtraInfoType = { extraInfo: string; }; // Mark the function as a generic using P (or whatever variable you want) export function withExtraInfo<P>( // Then we need to type the incoming component. // This creates a union type of whatever the component // already accepts AND our extraInfo prop WrappedComponent: React.ComponentType<P & ExtraInfoType> ) { const [extraInfo, setExtraInfo] = useState(''); setExtraInfo('important data.'); const ComponentWithExtraInfo = (props: P) => { // At this point, the props being passed in are the original props the component expects.
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-create-wrapper-components-in-react-with-props
How To Create Wrapper Components in React with Props | DigitalOcean
May 18, 2020 - This will be a wrapper component to create a standard style for any new card components. ... Create a component that takes children and title as props and wraps them in a div by adding the following code: ... import React from 'react'; import PropTypes from 'prop-types'; import './Card.css'; ...
🌐
React
react.dev › learn › typescript
Using TypeScript – React
There are two common paths to describing the children of a component. The first is to use the React.ReactNode type, which is a union of all the possible types that can be passed as children in JSX: ... This is a very broad definition of children. The second is to use the React.ReactElement type, which is only JSX elements and not JavaScript primitives like strings or numbers: ... Note, that you cannot use TypeScript to describe that the children are a certain type of JSX elements, so you cannot use the type-system to describe a component which only accepts <li> children.
🌐
Stevekinney
stevekinney.github.io › react-and-typescript › higher-order-components
Higher Order Components with TypeScript – Higher Order Components – React && TypeScript
So, we're passing that in and then whatever else that component might choose to take down the road. The end result looks something like this and can be found here. import * as React from "react"; import { CharacterType, fetchCharacter } from "./characters"; import { Loading } from "./Loading"; import { CharacterInformation } from "./CharacterInformation"; type WithCharacterProps = { character: CharacterType; }; function withCharacter<T extends WithCharacterProps>( Component: React.ComponentType<T> ) { return (props: Omit<T, keyof WithCharacterProps>) => { const [character, setCharacter] = Reac
🌐
Medium
medium.com › @a.g.stranger › 4-different-ways-you-can-wrap-react-components-38b02302b07d
4 different ways you can wrap React components | by AhmƎd Ghrib (A.G. STRANGER) | Medium
February 12, 2023 - If you’ve been working with React for more than a year or two, you should definitely invest some in learning more about HOC. Anyway, back to this article. Let’s compare each of the different provided approaches: Use Case: The component prop is often used to pass a component to a wrapper component, to render it with additional functionality or styling.
Find elsewhere
🌐
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 - ComponentProps is especially popular in user interface libraries (like Shadcn) because it keeps all the props of your wrappers, including the children prop, perfectly in sync with the underlying element. This helps achieve type safety and reusability when extending existing components or building higher-order components. ... type ButtonProps = React.ComponentProps<'button'>; export const Button = (props: ButtonProps) => { return <button {...props} />; };
Top answer
1 of 2
1

You can do it with a combination of types and a utility function that will enforce the props for the given component:

type ComponentAndProps<C extends React.ElementType<any>> = [C, React.ComponentPropsWithRef<C>];
type WrapperSet = ComponentAndProps< React.ElementType<any> >[];

function makeGroup<C extends React.ElementType<any>>(Component: C, props: React.ComponentPropsWithRef<C>): ComponentAndProps<C> {
    return [Component, props];
}

Here's a usage example:

export const Container: React.FC = () => {
    // these could be any arbitrary wrapper components
    const wrappers: WrapperSet = [
        makeGroup(WrapperA, { label: "WrapperA" }),
        makeGroup(WrapperB, { title: "foo" }),
        makeGroup(WrapperB, {}),  // Error: missing 'title' property
    ];
  
    const content = <span>Original content</span>;
  
    return wrap(content, wrappers);
};

The trick is the makeGroup() helper function that allows TypeScript to infer and enforce the props type for the component.

If you just use the tuple notation then the props end up as any and TypeScript can't enforce the props:

    const wrappers2: WrapperSet = [
        [WrapperA, { label: "WrapperA" }],
        [WrapperB, {}]  // BAD - no error, TypeScript can't infer the props type for the component here
    ];

Final note - React has a number of utility types for extracting the props type from a component.

I chose ComponentPropsWithRef just in case you have a component that uses refs, but adjust as necessary:

React.ComponentProps<Component>
React.ComponentPropsWithRef<Component>
React.ComponentPropsWithoutRef<Component>
2 of 2
1

You can create type util which will accept two components and produce a tuple of wrappers and corresponding props:

import React, { FC, ComponentProps } from "react";

type Wrap<Comps extends FC<any>[]> = {
  [Comp in keyof Comps]: Comps[Comp] extends React.JSXElementConstructor<any>
  ? [Comps[Comp], ComponentProps<Comps[Comp]>]
  : never
}

type WrapperSet = Wrap<[typeof WrapperA, typeof WrapperB]>

export const Container: React.FC = () => {
  // these could be any arbitrary wrapper components
  const wrappers: WrapperSet = [
    [WrapperA, { label: "WrapperA" }],
    [WrapperB, { title: "foo" }],
  ];

  const content = <span>Original content</span>;

  return wrap(content, wrappers);
}; // compiles

But there is still a problem with:

function wrap(children: JSX.Element, wrappers: WrapperSet): JSX.Element {
  let content = children;

  wrappers.forEach((wrapper) => {
    const [ComponentType, props] = wrapper;
    content = <ComponentType {...props}>{content}</ComponentType>;
  });

  return content;
}

Likewise, multiple candidates for the same type variable in contra-variant positions causes an intersection type to be inferred.

This is why ComponentType expects an intersection of all props and not a union. TS is unable to figure out which prop correspond to each component in dynamic loop. In order to fix it, we need to create extra function:

const iteration = <Comp extends React.JSXElementConstructor<any>>(
  Comp: Comp,
  props: ComponentProps<Comp>,
  content: JSX.Element
) => <Comp {...props} >{content}</Comp>

And the whole code:

import React, { FC, ComponentProps } from "react";

type Wrap<Comps extends FC<any>[]> = {
  [Comp in keyof Comps]: Comps[Comp] extends React.JSXElementConstructor<any>
  ? [Comps[Comp], ComponentProps<Comps[Comp]>]
  : never
}

type WrapperSet = Wrap<[typeof WrapperA, typeof WrapperB]>


export const Container: React.FC = () => {
  // these could be any arbitrary wrapper components
  const wrappers: WrapperSet = [
    [WrapperA, { label: "WrapperA" }],
    [WrapperB, { title: "foo" }],
  ];

  const content = <span>Original content</span>;

  return wrap(content, wrappers);
};

const WrapperA: React.FC<{ label: string }> = ({ label, children }) => (
  <>
    <div>WrapperA: {label}</div>
    {children}
  </>
);

const WrapperB: React.FC<{ title: string }> = ({ title, children }) => (
  <>
    <div>WrapperB: {title}</div>
    {children}
  </>
);

const iteration = <Comp extends React.JSXElementConstructor<any>>(
  Comp: Comp,
  props: ComponentProps<Comp>,
  content: JSX.Element
) => <Comp {...props} >{content}</Comp>

function wrap(children: JSX.Element, wrappers: WrapperSet) {
  let content = children;

  wrappers.forEach((wrapper) => {
    const [ComponentType, props] = wrapper;
    content = iteration(ComponentType, props, content)
  });

  return content
}

Playground

🌐
React TypeScript Cheatsheets
react-typescript-cheatsheet.netlify.app › useful patterns by use case
Useful Patterns by Use Case | React TypeScript Cheatsheets
Then you can use ComponentPropsWithRef ... for your wrapper component. Check our docs on forwarding Refs for more. Why not ComponentProps or IntrinsicElements or [Element]HTMLAttributes or HTMLProps or HTMLAttributes? You CAN use ComponentProps in place of ComponentPropsWithRef, but you may prefer to be explicit about whether or not the component's refs are forwarded, which is what we have chosen to demonstrate. The tradeoff is slightly more intimidating terminology. More info: https://react-typescrip...
🌐
GitHub
github.com › react-bootstrap › react-bootstrap › issues › 5013
Can't specify correct types for a wrapper component around `Button`, in TypeScript · Issue #5013 · react-bootstrap/react-bootstrap
February 28, 2020 - I've written a wrapper component for Button. Like this: import { Button } from 'react-bootstrap'; function WrapperButton(props) { const { children } = props; return <Button {...props}>{children}</Button>; } Since I'm using this in TypeScript, I'm trying to add types to props.
Author   garyking
🌐
Stack Overflow
stackoverflow.com › questions › 59128218 › typescript-react-typing-a-functional-wrapper-component-that-extends-a-given-c
reactjs - Typescript + React: Typing a functional wrapper component that extends a given class component - Stack Overflow
December 1, 2019 - import React, { Component, ComponentType } from 'react' import Layout from './components/LayoutComponent' import { Route } from 'react-router' type LayoutRouteProps = { component: ComponentType, } const DashboardLayoutRoute = ({ component: Component, ...rest }: LayoutRouteProps) => { const render = (matchProps: any) => ( <Layout> <Component {...matchProps} /> </Layout> ) return ( <Route {...rest} render={render} /> ) }
🌐
Medium
medium.com › @mun1013 › react-typescript-part-1-94d5da740c2d
React + TypeScript — Part 1
September 14, 2024 - Moreover, it promotes type safety⛑️! ComponentPropsWithoutRef ensures that TypeScript knows which props are valid for the element you’re rendering. It will throw errors if you pass invalid props into it. // Container.tsx import { type ReactNode, type ElementType, type ComponentPropsWithoutRef, } from "react"; type ContainerProps<T extends ElementType> = { as?: T; children: ReactNode; } & ComponentPropsWithoutRef<T>; const Container = <C extends ElementType> ({ as, children, ...props }: ContainerProps<C>) => { const Component = as || "div"; return <Component {...props}>{children}</Component>; } export default Container; // use case // App.tsx const App = () => { return ( <div> <Container as="a" href="https://abc.com"> Link </Container> <Container as="button" onClick={() => alert('Button clicked!')}> Button </Container> </div> ); } export default App;
🌐
Lit
lit.dev › docs › frameworks › react
React – Lit
The React component wrapper enables setting properties on custom elements (instead of just attributes), mapping DOM events to React-style callbacks, and enables correct type-checking in JSX by TypeScript.
🌐
GitHub
github.com › testing-library › react-testing-library › issues › 970
Wrapper type breaks types with props other than children · Issue #970 · testing-library/react-testing-library
September 27, 2021 - Note: only certain maintainers handle TypeScript labeled issues.bugSomething isn't workingSomething isn't working ... type AppWrapperProps = { userProviderProps?: UserProviderProps } export const AppWrapper: React.FC<AppWrapperProps> = ({ children, userProviderProps = { user: mockUser }, }) => ( <UserProvider {...userProviderProps}> ... ... The type being inflexible (only allowing children) means that the wrapper can't take props if used anywhere else
🌐
Pluralsight
pluralsight.com › blog › guides
Composing React Components with TypeScript | Online Courses, Learning Paths, and Certifications - Pluralsight
Higher-order components are a powerful pattern but it does require some work to ensure the TypeScript compiler understands how to strongly-typed the wrapper and wrapped components. Note: Most issues with HOCs and TypeScript are due to improper or mismatching type annotations. Remember that in React, a consumer and the component itself may expect different props to be available since HOCs add props on top of what a component expects by itself.
🌐
GitHub
gist.github.com › kitze › 23d82bb9eb0baabfd03a6a720b1d637f
one-line React component for conditionally wrapping children · GitHub
typescript version: type ConditonalWrapperProps = { children: React.ReactElement; condition: boolean; wrapper: (children: React.ReactElement) => JSX.Element; }; const ConditonalWrapper: React.FC<ConditonalWrapperProps> = ({ condition, wrapper, ...