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:
optional_websocket.ts
ws?: WebSocket = undefined;Check out similar posts by category:
Angular, Javascript
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow