I am trying to make a filter system and run into a problem.
I set a few types:
type Brand = {
brand:string;
checked:boolean;
}
type Gender = {
gender: "Male" | "Female" | "Kids";
checked:boolean;
}
type Shoes = {
brand:Brand;
gender:Gender;
}
and then i’m trying to create a useState object like this:
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,
}
],
});
However on the key brand and gender i’m getting this type of error:
Type '{ brand: string; checked: false; }[]' is missing the following properties from type 'Brand': brand, checked
even though i’m adding all the type properties. Any help would be appreciated.
>Solution :
You need to specify that your brand property and your gender property are arrays:
type Shoes = {
brand: Brand[]; // or Array<Brand>
gender: Gender[]; // or Array<Gender>
}
Probably better to name your properties brands and genders though.