Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

286
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

0

I think you should write like this...

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

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda