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

204
Vistas
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 Respuestas
Responde la pregunta

0

You can type collapseStates as a Record:

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