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'.
}
CodePudding user response:
The type of displayBasic is boolean, while setDisplayBasic sets the value of the state. To fix this put displayBasic where you have setDisplayBasic.
CodePudding user response:
setDisplayBasic is a function, the boolean is displayBasic. Your code should look like this:
const dialogFuncMap: Record<string, boolean> = {
'displayBasic': displayBasic
}