Typescript class malfunctions when used as a type in another class's property

I’m using mediasoap and typescript in an express server application and here’s the Broadcast type that i defined which has a property of type Router (a class defined in mediasoup module) and here’s the problem:

Upon creating an instance of broadcast the router does not get created properly and here’s why:

  1. I cannot log the created object in console (console.log output: [object Object])
  2. There’s an array as a 3rd level nested property in router object called codecs, which is very important and it doesn’t get set upon creation.

But when I create the router object separately it works just fine! even if I create the broadcast object with a null value for the router and then set the router property with the separately created fine working router object it again stops behaving properly

Broadcast Class:

import { types } from "mediasoup";

export class Broadcast {
  Id: string;
  Title: string;
  Router: types.Router;
  Streamer: Streamer;
  Participants: Array<Participant>;

Here’s a scenario to demonstrate the problem

BroadcastService Class:

export class BroadcastService {

  _streamerService: StreamerService;

  constructor() {
    this._streamerService = new StreamerService();
  async CreateBroadcast(title: string, streamer: Streamer): Promise<Broadcast> {

    var broadcast: Broadcast = {
      Title: title,
      Id: uuidv4(),
      Streamer: this._streamerService.CreateStreamer(streamer.Id),
      Router: null,
      Participants: new Array<Participant>()
    return broadcast;

Separated Instantiation:

var broadcast = await broadcastService.CreateBroadcast();
console.log(broadcast.Router); // null due to Broadcast constructor
var mediaCodecs = config.router.mediaCodecs;
var router = await this.Worker.createRouter({ mediaCodecs });
console.log(router.rtpCapabilities.codecs); // logs the correct codecs
broadcast.Router = router;
console.log(broadcast.Router.rtpCapabilities.codecs); // result: [object Object],[object Object],[object Object]

^ is how objects are logged in JavaScript when they are nested in some other object, I see no malfunctioning on mediasoup side.

Try console.log(JSON.stringify()), it might produce something closer to what you expect.

there is no malfunction on mediasoap side
but as I mention the RtpCodecCapabalities are not assigned to the router when the router is pass to the broadcast and that’s the main problem

I don’t see that problem, according to your snippet it is logged just fine in the console, so where is the problem exactly?