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

244
Vistas
No index signature with a parameter of type 'string' Error in TypeScript while giving types to Objects

I was converting my ReactJS app written in JS to Typescript.

I am getting this error:

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'topBarType'. No index signature with a parameter of type 'string' was found on type 'topBarType'.

type topBarType = {
    height: string;
    "font-size": string;
    iconWidth: string;
    iconHeight: string;
};
type variantTypes = 'sm'|'md'|'lg';

export function topBarTheme(variant: variantTypes, property: string): string {
    const theme: { [key: string]: topBarType } = {
        sm: {
            height: `height:2rem;`,
            "font-size": `font-size: 1.5rem;`,
            iconWidth: `width: 1.75rem;`,
            iconHeight: `height: 1.75rem;`,
        },
        md: {
            height: `height:2.5rem;`,
            "font-size": `font-size: 1.75rem;`,
            iconWidth: `width: 2rem;`,
            iconHeight: `height: 2rem;`,
        },
        lg: {
            height: `height:3rem;`,
            "font-size": `font-size: 2rem;`,
            iconWidth: `width: 2.5rem;`,
            iconHeight: `height: 2.5rem;`,
        },
    };

    if (!variant) return theme["lg"][property]; <-- Error
    return theme[variant][property]; <-- Error
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Try defining the type for the property argument:

type topBarProperties = keyof topBarType;

export function topBarTheme(
  variant: variantTypes,
  property: topBarProperties
): 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