Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

111
Vistas
Dynamic construction of React component with Typescript annotations

I created a short demo for the demonstration. The point is, I want to create React components using my own customCreate service. But I want to check the properties of the input component. When I declared the inputs in customCreate to any, everything is fine, but there is no type check by Typescript.

My condition is the ability to create different components using customCreate.

What types should I set in the customCreate function to make everything work properly with type checking? Thanks

interface IDemoObjectProps {
    demoprop1: string,
    demoprop2: number
};

class DemoComponent extends React.Component<IDemoObjectProps> {
    render() {
        return <></>
    }
}

// Annotation?
const customCreate = (type: any, props: any) => {
    return React.createElement(type, props);
};

// Create React element
const component1 = customCreate(DemoComponent, {demoprop1: 'demo', demoprop2: 2022});
console.log(component1);
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda