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

203
Visualizações
rxjs argument of type 'Element | null' is not assignable to parameter of type JQueryStyleEventEmitter

I'm new to rxjs, When try to create event for incrementButton, it throw error as

No overload matches this call.
The last overload gave the following error.
Argument of type 'Element | null' is not assignable to parameter of type 'JQueryStyleEventEmitter<any, unknown> | ArrayLike<JQueryStyleEventEmitter<any, unknown>>'.
Type 'null' is not assignable to type 'JQueryStyleEventEmitter<any, unknown> | ArrayLike<JQueryStyleEventEmitter<any, unknown>>'.  TS2769

In the below snippet Line:8 Col:35 incrementButton throw error

import { Fragment, useState } from "react";
import { fromEvent } from "rxjs";

const SimpleCounter = () => {
  const [result, setResult] = useState(0);

  const incrementButton = document.querySelector("incBtn");
  const increaseCount = fromEvent(incrementButton, "click");

  return (
    <Fragment>
      <h1>{result}</h1>
      <button id="incBtn">Increase</button>
    </Fragment>
  );
};

I tried type casting like below still it got failed

const increaseCount = fromEvent(<JqueryStyleEventEmitter> <unknow> incrementButton, "click");
const increaseCount = fromEvent(incrementButton as JqueryStyleEventEmitter as unknown, "click");
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

There are 2 changes I have done to my code. Now it is working.

  1. type conversion to querySelector using HTMLButtonElement
const incrementButton = document.querySelector(
  "#incBtn"
) as HTMLButtonElement;
  1. Moved button selection code in to the useEffect hook.
useEffect(() => {
  const incrementButton = document.querySelector(
    "#incBtn"
  ) as HTMLButtonElement;
  const increaseCount = fromEvent(incrementButton, "click");
  increaseCount.subscribe(() => {setResult(result++)});
});
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