我正在尝试制作一个过滤系统,但遇到了问题。 我设置了几种类型:
type Brand = { brand:string; checked:boolean; } type Gender = { gender: "Male" | "Female" | "Kids"; checked:boolean; } type Shoes = { brand:Brand; gender:Gender; }
然后我尝试创建一个如下所示的 useState 对象:
const [filterState,setFilterState] = useState<Shoes>({ brand:[ { brand:'New Balance', checked: false, }, { brand:'Nike', checked: false, }, { brand:'Addiddas', checked: false, }, { brand:'Puma', checked: false, }, { brand:'Converse', checked: false, }, { brand:'Under Armour', checked: false, }, ], gender:[{ gender:'Male', checked:false, }, { gender:'Female', checked:false, }, { gender:'Kids', checked:false, } ], });
但是,在关键品牌和性别上,我遇到了此类错误:
Type '{ brand: string; checked: false; }[]' is missing the following properties from type 'Brand': brand, checked
即使我添加了所有类型属性。任何帮助将不胜感激。
您需要指定您的
brand
属性和gender
属性是数组:最好将您的属性命名为
brands
和ngenders
。