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

187
Views
Type 'undefined' cannot be used as an index type.ts(2538)

I'm typescript beginner, i have set types for props as you can see but getting error: Type 'undefined' cannot be used as an index type.ts(2538) (property) AA.action?: string | undefined

any advice/help ? my code:

interface AA {
  action?: string;
  actionArgs?: string;
}

const ArticleList: React.FC<AA> = (props) => {
  const data = useSelector((state: RootStateOrAny) => {
    const secondData = {
      sites: state.articles.sites,
      analysers: state.siteArticles.analysers,
    };

    return secondData[props.action];
  });

if i remove optional then getting more errors: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ sites: any; analysers: any; }'. No index signature with a parameter of type 'string' was found on type '{ sites: any; analysers: any; }'.ts(7053)

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

interface AA {
  action: keyof MySecondData;
  actionArgs?: string;
}

interface MySecondData {
  sites: string_I_guess[],
  analysers: Analysers[],
};

const ArticleList: React.FC<AA> = (props) => {
  const data = useSelector((state: RootStateOrAny) => {
    const secondData: MySecondData = {
      sites: state.articles.sites,
      analysers: state.siteArticles.analysers,
    };

    return secondData[props.action];
  });

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!