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

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

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 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!