Typescript: Interface types missing in class object generation from JSON file

I’m trying to load a JSON file into a Array of class objects. But I receive the following error:

Argument of type ‘(room: IRoomManager) => RoomManager’ is not
assignable to parameter of type ‘(value: { id: number; name: string;
description: string; participants: never[]; capacity: number; status:
boolean; }, index: number, array: { id: number; name: string;
description: string; participants: never[]; capacity: number; status:
boolean; }[]) => RoomManager’. Types of parameters ‘room’ and
‘value’ are incompatible.
Type ‘{ id: number; name: string; description: string; participants: never[]; capacity: number; status: boolean; }’ is
missing the following properties from type ‘IRoomManager’: getId,
getName, getDescription, getParticipants, and 7 more.

Is this caused because I added the functions from the RoomManager class to the interface or what is causing this issue?

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>initializeRooms = () => {
this.rooms = RoomConfig.map(
(room: IRoomManager) =>
new RoomManager(
room.id,
room.name,
room.description,
room.participants,
room.capacity,
room.status,
),
);
logger.gameDebugMessage(`${this.rooms.length} rooms initialized`);
};
</code>
<code>initializeRooms = () => { this.rooms = RoomConfig.map( (room: IRoomManager) => new RoomManager( room.id, room.name, room.description, room.participants, room.capacity, room.status, ), ); logger.gameDebugMessage(`${this.rooms.length} rooms initialized`); }; </code>
initializeRooms = () => {
  this.rooms = RoomConfig.map(
    (room: IRoomManager) =>
      new RoomManager(
        room.id,
        room.name,
        room.description,
        room.participants,
        room.capacity,
        room.status,
      ),
  );

  logger.gameDebugMessage(`${this.rooms.length} rooms initialized`);
};

which is supposed to load a imported JSON file:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>const rooms = [
{
id: 1,
name: 'Room 1',
description: 'Example',
participants: [],
capacity: 20,
status: true,
},
{
id: 2,
name: 'Room 2',
description: 'Example',
participants: [],
capacity: 20,
status: true,
},
];
export default rooms;
</code>
<code>const rooms = [ { id: 1, name: 'Room 1', description: 'Example', participants: [], capacity: 20, status: true, }, { id: 2, name: 'Room 2', description: 'Example', participants: [], capacity: 20, status: true, }, ]; export default rooms; </code>
const rooms = [
  {
    id: 1,
    name: 'Room 1',
    description: 'Example',
    participants: [],
    capacity: 20,
    status: true,
  },
  {
    id: 2,
    name: 'Room 2',
    description: 'Example',
    participants: [],
    capacity: 20,
    status: true,
  },
];

export default rooms;

and write all rooms to a array: rooms: RoomManager[]; which is of the type of the RoomManager class:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import IRoomManager from '../interfaces/IRoomManager';
import IClientRoomData from '../interfaces/IClientRoomData';
import PlayerManager from './player.manager';
class RoomManager implements IRoomManager {
id: number;
name: string;
description: string;
participants: PlayerManager[];
capacity: number;
status: boolean;
constructor(
id: number,
name: string,
description: string,
participants: PlayerManager[],
capacity: number,
status: boolean,
) {
this.id = id;
this.name = name;
this.description = description;
this.participants = participants;
this.capacity = capacity;
this.status = status;
}
getId = (): number => this.id;
getName = (): string => this.name;
getDescription = (): string => this.description;
getParticipants = (): PlayerManager[] => this.participants;
getCapacity = (): number => this.capacity;
getStatus = (): boolean => this.status;
setDescription = (description: string) => {
this.description = description;
};
setParticipants = (participants: PlayerManager[]) => {
this.participants = participants;
};
setCapacity = (capacity: number) => {
this.capacity = capacity;
};
setStatus = (status: boolean) => {
this.status = status;
};
generateRoomList = (): IClientRoomData => {
return {
id: this.id,
name: this.name,
description: this.description,
participant_count: this.participants.length,
capacity: this.capacity,
status: this.status,
};
};
}
export default RoomManager;
</code>
<code>import IRoomManager from '../interfaces/IRoomManager'; import IClientRoomData from '../interfaces/IClientRoomData'; import PlayerManager from './player.manager'; class RoomManager implements IRoomManager { id: number; name: string; description: string; participants: PlayerManager[]; capacity: number; status: boolean; constructor( id: number, name: string, description: string, participants: PlayerManager[], capacity: number, status: boolean, ) { this.id = id; this.name = name; this.description = description; this.participants = participants; this.capacity = capacity; this.status = status; } getId = (): number => this.id; getName = (): string => this.name; getDescription = (): string => this.description; getParticipants = (): PlayerManager[] => this.participants; getCapacity = (): number => this.capacity; getStatus = (): boolean => this.status; setDescription = (description: string) => { this.description = description; }; setParticipants = (participants: PlayerManager[]) => { this.participants = participants; }; setCapacity = (capacity: number) => { this.capacity = capacity; }; setStatus = (status: boolean) => { this.status = status; }; generateRoomList = (): IClientRoomData => { return { id: this.id, name: this.name, description: this.description, participant_count: this.participants.length, capacity: this.capacity, status: this.status, }; }; } export default RoomManager; </code>
import IRoomManager from '../interfaces/IRoomManager';
import IClientRoomData from '../interfaces/IClientRoomData';
import PlayerManager from './player.manager';

class RoomManager implements IRoomManager {
  id: number;
  name: string;
  description: string;
  participants: PlayerManager[];
  capacity: number;
  status: boolean;

  constructor(
    id: number,
    name: string,
    description: string,
    participants: PlayerManager[],
    capacity: number,
    status: boolean,
  ) {
    this.id = id;
    this.name = name;
    this.description = description;
    this.participants = participants;
    this.capacity = capacity;
    this.status = status;
  }

  getId = (): number => this.id;
  getName = (): string => this.name;
  getDescription = (): string => this.description;
  getParticipants = (): PlayerManager[] => this.participants;
  getCapacity = (): number => this.capacity;
  getStatus = (): boolean => this.status;

  setDescription = (description: string) => {
    this.description = description;
  };

  setParticipants = (participants: PlayerManager[]) => {
    this.participants = participants;
  };

  setCapacity = (capacity: number) => {
    this.capacity = capacity;
  };

  setStatus = (status: boolean) => {
    this.status = status;
  };

  generateRoomList = (): IClientRoomData => {
    return {
      id: this.id,
      name: this.name,
      description: this.description,
      participant_count: this.participants.length,
      capacity: this.capacity,
      status: this.status,
    };
  };
}

export default RoomManager;

The implemented interface looks like the following:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import PlayerManager from './IPlayerManager';
import IClientRoomData from './IClientRoomData';
interface IRoomManager {
id: number;
name: string;
description: string;
participants: PlayerManager[];
capacity: number;
status: boolean;
getId: () => number;
getName: () => string;
getDescription: () => string;
getParticipants: () => PlayerManager[];
getCapacity: () => number;
getStatus: () => boolean;
setDescription: (description: string) => void;
setParticipants: (participants: PlayerManager[]) => void;
setCapacity: (capacity: number) => void;
setStatus: (status: boolean) => void;
generateRoomList: () => IClientRoomData;
}
export default IRoomManager;
</code>
<code>import PlayerManager from './IPlayerManager'; import IClientRoomData from './IClientRoomData'; interface IRoomManager { id: number; name: string; description: string; participants: PlayerManager[]; capacity: number; status: boolean; getId: () => number; getName: () => string; getDescription: () => string; getParticipants: () => PlayerManager[]; getCapacity: () => number; getStatus: () => boolean; setDescription: (description: string) => void; setParticipants: (participants: PlayerManager[]) => void; setCapacity: (capacity: number) => void; setStatus: (status: boolean) => void; generateRoomList: () => IClientRoomData; } export default IRoomManager; </code>
import PlayerManager from './IPlayerManager';
import IClientRoomData from './IClientRoomData';

interface IRoomManager {
  id: number;
  name: string;
  description: string;
  participants: PlayerManager[];
  capacity: number;
  status: boolean;
  getId: () => number;
  getName: () => string;
  getDescription: () => string;
  getParticipants: () => PlayerManager[];
  getCapacity: () => number;
  getStatus: () => boolean;
  setDescription: (description: string) => void;
  setParticipants: (participants: PlayerManager[]) => void;
  setCapacity: (capacity: number) => void;
  setStatus: (status: boolean) => void;
  generateRoomList: () => IClientRoomData;
}

export default IRoomManager;

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật