[SOLVED] Property 'value' does not exist on type 'EventTarget'.ts(2339) – TypeScript

Issue

I’m trying to use onChange function on a slider, but I keep getting and error with the Value. Am I doing something wrong ?

I’m using TypeScript and ViteJS.

Value error

My code:

      <Slider
        color="success"
        aria-label="Small steps"
        defaultValue={0.00000005}
        step={1}
        marks
        min={5}
        max={20}
        valueLabelDisplay="auto"
        value={passwordLength}
        onChange={(e) => setPasswordLength(e.target.value)}
      />

Solution

Looking at the error reported:
Property ‘value’ does not exist on type ‘EventTarget’

Since you are using a custom component <Slider>, you need to explicitly tell TypeScript the type of the HTMLElement which is your target.

Look at this for more details

Answered By – Sandro Maglione

Answer Checked By – David Marino (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *