* Runtime-checked field readers for untyped server events. Replace the * drive-by `event.X as string` / `event.X as Record ` casts * with readers that return `undefined` when the shape doesn't match, so a * malformed frame can't throw a TypeError inside `handleServerEvent`.
( obj: Record<string, unknown>, key: string, )
| 23 | * malformed frame can't throw a TypeError inside `handleServerEvent`. |
| 24 | */ |
| 25 | function readString( |
| 26 | obj: Record<string, unknown>, |
| 27 | key: string, |
| 28 | ): string | undefined { |
| 29 | const value = obj[key] |
| 30 | return typeof value === 'string' ? value : undefined |
| 31 | } |
| 32 | |
| 33 | function readObject( |
| 34 | obj: Record<string, unknown>, |
no outgoing calls
no test coverage detected