Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

215
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!