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

175
Views
Typescript error message ',' expected.ts(1005)

I keep getting the error message ',' expected.ts(1005) when trying to dynamically render a modal on Typescript. I'm almost certainly missing a closing curly bracket somewhere but cant figure out where.

      `<div class="modalWrap">
      <h2 class="modalHeader">Shop The Look</h2>
      <div class="modalContent">${object.map((el) => 
      `<div class="prodDetails">
        <img class="prodImg" alt="prodImage" src = ${el.primaryImage.url}></img>
        <p class="prodName">${el.name}</p>
        <p class="prodPrice">${el.price.value}</p>
        <div class = "selectWrapper">
    <div class="selectNumber">
    <div class="numberWrapper"> 
  ${el.sizeOptions
    .map(
      (option) => `
      <p class="selectSize" >${option.value}</p>`
    )
    .join('')}
    </div>
    </div>
    </div>
    </div>
    </div>
    )}
    </div>`

Any help would be appreciated!

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

0

You didn't close the string literal that was being mapped from object:

const test = `<div class="modalWrap">
<h2 class="modalHeader">Shop The Look</h2>
<div class="modalContent">${object.map(
    (el) =>
        `<div class="prodDetails">
  <img class="prodImg" alt="prodImage" src = ${el.primaryImage.url}></img>
  <p class="prodName">${el.name}</p>
  <p class="prodPrice">${el.price.value}</p>
  <div class = "selectWrapper">
<div class="selectNumber">
<div class="numberWrapper"> 
${el.sizeOptions
    .map(
        (option) => `
<p class="selectSize" >${option.value}</p>`
    )
    .join('')}
</div>
</div>
</div>
</div>
</div>`
)}

</div>`;
about 4 years ago · Juan Pablo Isaza Report

0

Less of an answer than a rant with good intentions.

This code is illegible, and because of that, finding the missing backtick is extremely tedious. Here's how to make it less awful. * Edited for brevity.

Step 1: Indent. We're not savages.

This step alone is enough to resolve the issue.

`
<div class="modalWrap">
  <h2 class="modalHeader">Shop The Look</h2>
  <div class="modalContent">
    ${object.map(el => `
      <div class="prodDetails">
        <img class="prodImg" alt="prodImage" src = ${el.primaryImage.url}></img>
        <p class="prodName">${el.name}</p>
        <p class="prodPrice">${el.price.value}</p>
        <div class = "selectWrapper">
          <div class="selectNumber">
            <div class="numberWrapper"> 
              ${el.sizeOptions.map(option => `
                <p class="selectSize" >${option.value}</p>
              `).join('\n')}
            </div>
          </div>
        </div>
      </div>
    `).join('\n')}
  </div>
</div>
`

Step 2: Don't do so much at once. Let your code breathe.

There are two pseudo-"components" to pull out, both functions to map. This clarifies their intent and reduces the surface area of the mainline code.

The inner one is simple:

const makeOption = opt => `<p class="selectSize">${option.value}</p>`

The outer one is incrementally more complex, but by maintaining indentation, adding some clarifying whitespace, and using the inner "component", it's much cleaner:

const makeProdDetail = el => `
  <div class="prodDetails">
    <img class="prodImg" alt="prodImage" src=${el.primaryImage.url}></img>

    <p class="prodName">${el.name}</p>

    <p class="prodPrice">${el.price.value}</p>

    <div class="selectWrapper">
      <div class="selectNumber">
        <div class="numberWrapper"> 
          ${el.sizeOptions.map(makeOption).join('\n')}
        </div>
      </div>
    </div>
  </div>
`

The smaller the functional chunks are the easier spotting and mitigating mistakes is. It's also easier to modify/update/parameterize/etc.

Step 3: Tie it all together

Now the overall component is wee:

`
<div class="modalWrap">
  <h2 class="modalHeader">Shop The Look</h2>

  <div class="modalContent">
    ${object.map(makeProdDetail).join('\n')}
  </div>
</div>
`

All untested, but roughly correct.

Step 4: Give things meaningful names.

  • object => products
  • el => product
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!