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

281
Views
TS2322: Type 'Atrribute' is not assignable to type 'boolean | undefined'. Toggle

I tried first isToggle and onToggle to be a boolean type, but it still warning about the types after the change you can see below.

This is error of checked: Type 'Atrribute' is not assignable to type 'boolean | undefined'.

This is error of onChange : Type 'Atrribute' is not assignable to type 'ChangeEventHandler'. Type 'Atrribute' provides no match for the signature '(event: ChangeEvent): void'.

import React, {ChangeEventHandler} from "react";
import classNames from "classnames";
import './SwitchToggle.css';

interface Atrribute{
    rounded:boolean;
    isToggled:boolean|undefined;
    onToggle:ChangeEventHandler<HTMLInputElement>;
}

const SwitchToggle =(rounded:Atrribute ,isToggled:Atrribute,onToggle:Atrribute)=>{

    const sliderCX = classNames("slider",{
        "rounded":rounded
    })

    return(
        <label className={"switch"}>
            <input type={"checkbox"} checked={isToggled} onChange={onToggle}/>
            <span className={sliderCX}/>
        </label>
    )
}

export default SwitchToggle;

I also use this code in main and its work fine

const [isToggled,setTisToggled] = useState(false);

<SwitchToggle isToggled{...SwitchToggle.prototype.isToggled} onToggle={()=>setTisToggled(!SwitchToggle.prototype.isToggle)}/>
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

This isn't how you destructure function arguments:

const SwitchToggle = (rounded:Atrribute ,isToggled:Atrribute,onToggle:Atrribute) => {...}

What you're telling TypeScript here is that this function will receive three arguments, each of them being of type Atrribute. But instead this function will receive one argument, of type Atrribute, from which you want to destructure three properties.

To destructure an object, use the {} destructuring syntax:

const SwitchToggle = ({ rounded, isToggled, onToggle } : Atrribute) => {...}
about 4 years ago · Juan Pablo Isaza Report

0

I think you should write like this...

const SwitchToggle =({ rounded, isToggled ,onToggle }:Atrribute)=>{
about 4 years ago · Juan Pablo Isaza Report

0

Your props declaration is wrong. You can't write your props this way :

const SwitchToggle =(rounded:Atrribute ,isToggled:Atrribute,onToggle:Atrribute) => {...}

Atrribute is the type of your entire props object, so you should write it this way :

const SwitchToggle =(props:Atrribute) => {...}

Or, if you want to destructure your object, then it'll be something like :

const SwitchToggle =({rounded, isToggled, onToggle}:Atrribute) => {...}

P.S. : You misswrote Atrribute.

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!