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

214
Vistas
File importing with Typescript

I'm importing the file, but I can't give the type of the file, how can I solve this problem?

import { capitalize } from "utils";

import * as Icons from "./";
type IconType = {
  name: string;
};
const icon = ({ name, ...props }: IconType) => {
  const newName = capitalize(name);
  if (!Icons[newName]) return null;

  const CustomIcon = Icons[newName];
  return <CustomIcon {...props} />;
};

export default icon;

enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can probably fix your issue by typing Icons[newName as keyof Icons].

You have a lot of bad practices in your code you should fix, though:

  1. You should add a import * as icons from "./pathToIcons";. Importing by the index.ts should only happen if importing from outside the same folder;
  2. const icon = (...) A component should start with capital letter, const Icon = (...);
  3. { name, ...props }: IconType This is incoherent, because your type IconType only has one attribute name, therefore in your case, typescript should infer props typeof never. Probably you want something interface IconProps extends CustomIconProps { name: string }
about 4 years ago · Juan Pablo Isaza Denunciar
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