'Nestjs how to change socket.io message data

If the message data is not null, I can edit value like this:

context.switchToWs().getData().custom = true

But, how to change it, if the message data is null?



Solution 1:[1]

Try please this way:

const data = context.switchToWs().getData();

data = {
  ...data,
  custom: true
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Oro