我一直收到这条消息,尽管我认为我已经做了我需要做的事情来摆脱它。这就是这段代码的样子。
const toggleModal: boolean = useSelector<IRootState>(state => state.toggleModal)
// Here I get "Type 'unknown' is not assignable to type 'boolean'" when I hover toggleModal
[...]
useEffect(() => {
setModal(toggleModal) // Here I get the message
}, [toggleModal])
知道如何解决这个问题吗?
编辑:
这是我的 useState:
const [modal, setModal] = useState<IModal>({modal: false});
这就是我初始化 IRootState
接口的方式:
interface IRootState {
state: object;
toggleModal: boolean;
}
答案 0 :(得分:1)
(None, 3, 64)
不返回布尔值,因此您不能将其分配给布尔值。
你可以试试这个:
useSelector()
或者你可以这样做:
// leave the type out
const toggleModal = useSelector<IRootState>(state => state.toggleModal);