Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Typescript filter no signatures

I have a typescript error that say .filter no signatures. I am not sure how to fix this

interface IDevice {
    deviceId: string;
    deviceName?: string;
}

const joinRoom = ({ userId, deviceId, deviceName }: IRoomParams) => {
  rooms[userId] = rooms[userId]?.filter((id) => id !== deviceId);
})

Update: below I added all of my interface and the full function for joining a room. I am not sure how to structure my types so that I can use .filter to remote device from the list when device disconnects

const rooms: Record<string, Record<string, IDevice>> = {};
interface IDevice {
    deviceId: string;
    deviceName?: string;
}
interface IRoomParams extends IDevice {
    userId: string;
}

interface ISendRequestParams {
    userId: string;
    options: any;
    requestId: string;
}

interface IReturnRequestParams {
    userId: string;
    data: any;
    requestId: string;
    error: any;
}

const joinRoom = ({ userId, deviceId, deviceName }: IRoomParams) => {
    if (!rooms[userId]) rooms[userId] = {};
    // console.log('device joined the room', userId, deviceId, deviceName);
    rooms[userId][deviceId] = { deviceId, deviceName };
    socket.join(userId);
    
    io.sockets.to(userId).emit('get-devices', {
        userId,
        participants: rooms[userId]
    });

    socket.on('disconnect', () => {
        console.log(`user left the room: roomId[${userId}], device[${deviceId}], deviceName[${deviceName}]`);
        rooms[userId] = rooms[userId]?.filter((id) => id !== deviceId);
        socket.to(userId).emit('device-disconnected', deviceName);
    });
};

error:
This expression is not callable.
Type ‘IDevice’ has no call signatures.ts(2349)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If you want to remove the deviceId from your Record (dictionary) of devices associated to a userId, you can just use the delete operator:

The delete operator removes a property from an object.

delete rooms[userId][deviceId];
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading