Skip to content

Deserialization of json objects can fail silently #513

@sryhanen

Description

@sryhanen

Description
Common workflow when deserializing websocket messages from generic json objects is to cast them to the expected type:

MessageDTO<T> = {
 op:string
 data:T
}

interface Ping = {
 msgId:string
}

const message:MessageDTO<unknown>;
if(message.op === 'PING'){
   const pingMessage = message as MessageDTO<Ping>; 

Casting objects to other types won't cause runtime errors and this might cause undetected bugs.

Software version
11.6.1

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions