robtaussig / react-use-websocket

React Hook for WebSocket communication
MIT License
1.62k stars 135 forks source link

Fix a bug which lead no overload matching #213

Closed majiayu000 closed 8 months ago

majiayu000 commented 1 year ago

This pr fix a example bug for ts with a react >=18.2. It tuns like this:

TS2769: No overload matches this call.
  Overload 1 of 2, '(...items: ConcatArray<never>[]): never[]', gave the following error.
    Argument of type 'MessageEvent<any>' is not assignable to parameter of type 'ConcatArray<never>'.  
      Type 'MessageEvent<any>' is missing the following properties from type 'ConcatArray<never>': length, join, slice
  Overload 2 of 2, '(...items: ConcatArray<never>[]): never[]', gave the following error.
    Argument of type 'MessageEvent<any>' is not assignable to parameter of type 'ConcatArray<never>'.  
    11 |     useEffect(() => {
    12 |         if (lastMessage !== null) {
  > 13 |           setMessageHistory((prev) => prev.concat(lastMessage));
       |                                                   ^^^^^^^^^^^
    14 |         }
    15 |       }, [lastMessage, setMessageHistory]);
missinglink commented 9 months ago

Thank you, saved me a bunch of time. The example in the README doesn't work in typescript when copy-pasted verbatim, this patch resolves the issue.

robtaussig commented 8 months ago

@majiayu000 Released in 4.8.0!