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

208
Views
No index signature with a parameter of type 'string' was found on type '{}'.ts(7053)

I'm new to react typescript, here i have props and its types, everything is fine except this part : collapseStates["" + el.name + el.identifier] = true; it gives error: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'. No index signature with a parameter of type 'string' was found on type '{}'.ts(7053)

what is the right way of adding : collapseStates = {} to interface AA? as you can see it should contain strings collapseStates["" + el.name + el.identifier] Any help or advice is appreciated

  interface AA{
  action: "sites" | "analysers";
  actionArgs?: string;
  name: string;
  identifier: string;
}
  
  const Article: React.FC<AA> = (props) => {

  let [state, setState] = useState<AA>({
    actionArgs: props.actionArgs,
    collapseStates: {} ,
  });
 const handleExpandClick = (event, key) => {
setState({
  collapseStates: {
    ...state.collapseStates,
    [key]: !state.collapseStates[key],
  },
});
  };

 const initialize = () => {
    let collapseStates = {};
    articles.map((el: AA) => {
      collapseStates["" + el.name + el.identifier] = true;
      return;
    });

    setState({
      ...state,
      collapseStates: collapseStates,
    });
  };
  }

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

0

You can type collapseStates as a Record:

interface AA{
  ...
  collapseStates: Record<string,boolean>;
}
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!