I created an array type in typescript which looks like this
export type RamenApi = [
{
"Brand": string,
"Variety": string,
"Style": string,
"Country": string,
"Stars": number,
"Top Ten": string
}
]
Now, In one of the places, where I am sorting and filtering the array, I am getting the following error
Property '0' is missing in type '{ "Brand": string; "Variety": string; "Style": string; "Country": string; "Stars": number; "Top Ten": string; }[]' but required in type 'RamenApi'
Any idea on why I am getting the following error and how I can fix it?
type Props = {
searchData: RamenApi,
const [filteredSearch, setFilteredSearch] = useState<RamenApi | null>(null)
const {searchData} = props
const tempFilteredSearch = []
for (let i=0; i<searchData.length; i++) {
const currentResponse = searchData[i]
const searchVariable = currentResponse["Variety"].toLowerCase() + currentResponse["Brand"].toLowerCase() + currentResponse["Country"]
if (searchVariable.indexOf(text) > - 1) {
tempFilteredSearch.push(currentResponse)
}
}
setFilteredSearch(tempFilteredSearch.slice(0,5))
This is where I am getting error setFilteredSearch(tempFilteredSearch.slice(0,5))
. Also, the code is cut short. ignore missing brackets or any such mistakes