Typescript client examples have a version issue
brt-jeffrey-beaupre opened this issue · comments
i installed the packages:
$ npm install @foxglove/ws-protocol
$ npm install ws
and added some code:
import { FoxgloveClient } from "@foxglove/ws-protocol";
import WebSocket from "ws";
const address = 'ws://localhost:8765'
const client = new FoxgloveClient({
ws: new WebSocket(address, [FoxgloveClient.SUPPORTED_SUBPROTOCOL]),
});
but im getting a compiler error on IWebSocket:
$ ./node_modules/.bin/tsc
src/main.ts:21:5 - error TS2322: Type 'WebSocket' is not assignable to type 'IWebSocket'.
Types of property 'send' are incompatible.
Type '{ (data: BufferLike, cb?: ((err?: Error | undefined) => void) | undefined): void; (data: BufferLike, options: { mask?: boolean | undefined; binary?: boolean | undefined; compress?: boolean | undefined; fin?: boolean | undefined; }, cb?: ((err?: Error | undefined) => void) | undefined): void; }' is not assignable to type '(data: string | ArrayBuffer | ArrayBufferView | Blob, options?: { fin?: boolean | undefined; } | undefined) => void'.
Types of parameters 'data' and 'data' are incompatible.
Type 'string | ArrayBuffer | ArrayBufferView | Blob' is not assignable to type 'BufferLike'.
Type 'Blob' is not assignable to type 'BufferLike'.
Type 'Blob' is missing the following properties from type 'Buffer': write, toJSON, equals, compare, and 95 more.
21 ws: new WebSocket(address, [FoxgloveClient.SUPPORTED_SUBPROTOCOL]),
~~
node_modules/@foxglove/ws-protocol/dist/esm/src/FoxgloveClient.d.ts:23:9
23 ws: IWebSocket;
~~
The expected type comes from property 'ws' which is declared here on type '{ ws: IWebSocket; }'
Found 1 error in src/main.ts:21
I've tried using the same ws version as the example, but the example protocol library is very out of date.
An up to date working example would be greatly appreciated!