I'am trying to create converter function and it works good, but eslint is showing me error
export const convertRoomsInFloorToObj = (floors: IFloorServer[]): IFloor[] =>
floors.map(({rooms, ...another}: IFloorServer) => ({
rooms: rooms // Property 'rooms' does not exist on type 'IFloorServer'
.reduce(
// operation with array
),
...another,
}));
The problem is that rooms is declared:
export type IFloor = {
floor_number: number;
count_of_rooms: number;
rooms: IRooms;
};
export type IFloorServer = {
floor_number: number;
count_of_rooms: number;
rooms: IRooms; // here
} | null;
export type IRoom = {
// Room props
};
What I have to do to fix eslint error message?
You get this error because IFloorServer
can be an object or null because of | null
null
IFloorServer
'rooms'
cannot exist on type 'IFloorServer'