How to use optional type in Angular / TypeScript
If you have a variable called ws
of type WebSocket
, you can not assign null
or undefined
to that variable
In order to make a variable that is either of the given type or undefined
, use the following syntax:
ws?: WebSocket = undefined;