我正在尝试制作一个过滤系统,但遇到了问题。 我设置了几种类型:
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({ 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
即使我添加了所有类型属性。任何帮助将不胜感激。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
您需要指定您的
brand属性和gender属性是数组:type Shoes = { brand: Brand[]; // or Array
gender: Gender[]; // or Array
} 最好将您的属性命名为
brands和ngenders。