Dmitriy_kzn
Dmitriy_kzn

Reputation: 578

TS2322: Type Element is not assignable to type 'boolean'

I'm new with TypeScript, try to type my const dialogFuncMap but recieve an Error (on comments below). Why i get this error, if type of state is boolean ? How to fix it? (except any)

state:

const [displayBasic, setDisplayBasic] = useState<boolean>(false);

function:

const dialogFuncMap: Record<string, boolean> = {
        'displayBasic': setDisplayBasic, // TS2322: Type 'Dispatch<SetStateAction<boolean>>' is not assignable to type 'boolean'.
    }

Upvotes: 0

Views: 1107

Answers (2)

Aladiah
Aladiah

Reputation: 13

setDisplayBasic is a function, the boolean is displayBasic. Your code should look like this:

const dialogFuncMap: Record<string, boolean> = {
        'displayBasic': displayBasic
    }

Upvotes: 0

rgodha24
rgodha24

Reputation: 61

The type of displayBasic is boolean, while setDisplayBasic sets the value of the state. To fix this put displayBasic where you have setDisplayBasic.

Upvotes: 1

Related Questions