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

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

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