Property 'key' does not exist on type 'object'.
// component.ts
// useState
const [locationFloor, setLocationFloor] = useState<CabinetLocationFloorDto>();
// Axios
useEffect(() => {
axiosLocationFloor()
.then((response) => {
setLocationFloor(response.data.space_data);
})
.catch((error) => {
console.error(error);
});
}, []);
// prop 전달
<LocationButton
locations={locationFloor?.space_data?.map((e) => e.location)}
currentLocation={currentLocation}
setCurrentLocation={setCurrentLocation}
/>
// .dto.ts
export interface CabinetLocationFloorDto {
space_data: Array<object>;
}
Property 'location' does not exist on type 'object'.
에러가 발생하였다.interface spaceData {
location: string;
floors: Array<number>;
}
export interface CabinetLocationFloorDto {
space_data: Array<spaceData>;
}
// .dto.ts
export interface CabinetLocationFloorDto {
location: string;
floors: Array<number>;
}
// component.ts
const [locationFloor, setLocationFloor] = useState<CabinetLocationFloorDto[]>();
useEffect(() => {
axiosLocationFloor()
.then((response) => {
setLocationFloor(response.data.space_data);
})
.catch((error) => {
console.error(error);
});
}, []);
<LocationButton
locations={locationFloor?.map(
(e: CabinetLocationFloorDto) => e.location
)}
currentLocation={currentLocation}
setCurrentLocation={setCurrentLocation}
/>