我正在使用 zustand 和 typescript。我的代码出现此错误
Property 'filter' does not exist on type 'object'.ts(2339)
我不知道如何解决这个问题。我正在从我的 useStore 库创建一个对象。我尝试使用“类型”,但它在代码编辑器错误中引发了这些 错误
TS
import React from "react";
import "./App.css";
import create from "zustand";
type PkState = {
filter: "",
pokemon: [],
}
const useStore = create((PkState) => ({
PkStateFilter: (filter) =>
PkState((state) => ({
...state,
filter,
})),
PkStatePokemon: (pokemon) =>
PkState((state) => ({
...state,
pokemon,
})),
}));
// input
const FilterInput = () => {
const filter = useStore((state) => state.filter);
const PkStateFilter = useStore((state) => state.PkStateFilter);
return ( <input value={filter} onChange=((evt)=>PkStateFilter(evt.target.value)) />
)
};
function App() {
return <div className="App"></div>;
}
export default App;