Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

184
Visualizações
Typescript: unexpected token when using "as HTMLElement" type

I am new to Typescript. I am getting the following error when using the HTMLElement type within a forEach loop:

ERROR in ./app/javascript/mount.jsx
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: /Users/me/projects/mathllc/app/javascript/mount.jsx: Unexpected token, expected "," (7:34)

   5 |     const mountPoints = document.querySelectorAll('[data-react-component]')
   6 |     mountPoints.forEach((mountPoint) => {
>  7 |       const dataset = (mountPoint as HTMLElement).dataset
     |                                   ^
   8 |       const componentName = dataset['reactComponent']
   9 |       const Component = components[componentName]
  10 |       if (Component) {

I am following this tutorial by @Ryan Bigg : https://egghead.io/blog/rails-graphql-typescript-react-apollo

My code is here:

import ReactDOM from 'react-dom'
export default function mount(components = {}) {
  document.addEventListener('DOMContentLoaded', () => {
    const mountPoints = document.querySelectorAll('[data-react-component]')
    mountPoints.forEach((mountPoint) => {
      const dataset = (mountPoint as HTMLElement).dataset
      const componentName = dataset['reactComponent']
      const Component = components[componentName]
      if (Component) {
        const props = JSON.parse(dataset['props'])
        ReactDOM.render(<Component {...props} />, mountPoint)
      } else {
        console.log(
          'WARNING: No component found for: ',
          dataset.reactComponent,
          components,
        )
      }
    })
  })
}

Thanks for any help!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Looking at the error - ERROR in ./app/javascript/mount.jsx) - it appears that you are not using a .tsx file and the keyword as is not valid Javascript so you either should remove the as HTMLElement because Javascript does not care about types or change the filename to mount.tsx - if you are using a Typescript compiler in your build chain.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda