如何在 Angular / TypeScript 中使用可选类型
如果你有一个类型为 WebSocket 的变量 ws,你不能将 null 或 undefined 分配给该变量
为了使变量为给定类型或 undefined,使用以下语法:
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