Optional Types
i had a typescript error in my code and that was "Property 'onDisconnect' or 'onConnection' does not exist on type '{ isActive: boolean; onNewOrders: (newOrderIDS: string[]) => void; onConnection?: (() => void) | undefined; onDisconnect?: (() => void) | undefined; } | undefined'." The issue arises because TypeScript doesn't infer the properties properly when destructuring from an optional object (ordersSocket in this case). Even though onConnection and onDisconnect are defined as optional in the IProps interface, TypeScript still flags them as potentially non-existent.
Solution 1: Add Type Narrowing Before Destructuring
Check that ordersSocket exists and has properties before destructuring.
Solution 2: Explicit Type Assertion
If you are certain that ordersSocket will always be defined when used, you can assert its type to avoid optional chaining or unnecessary checks.