websocket-as-promised icon indicating copy to clipboard operation
websocket-as-promised copied to clipboard

bug: build in typescript Found 4 errors.

Open richenlin opened this issue 3 years ago • 0 comments

used in typescript:

  import WebSocketAsPromised from 'websocket-as-promised';
  
  const wsp = new WebSocketAsPromised(this.options.address, {
              createWebSocket: url => new WebSocket(url),
              extractMessageData: event => event, // <- this is important
              packMessage: data => JSON.stringify(data),
              unpackMessage: data => {
                  if (Helper.isJSONStr(<string>data)) {
                      return JSON.parse(<string>data);
                  } else {
                      return data;
                  }
              },
              attachRequestId: (data, requestId) => Object.assign({ id: requestId }, data), // attach requestId to message as `id` field
              extractRequestId: data => data && data.id,
          });

        return wsp.open().then(() => {
            this.service = wsp;
            return wsp;
        });

run build tsc throw errors:

  node_modules/websocket-as-promised/types/index.d.ts:9:9 - error TS2304: Cannot find name 'WebSocket'.
  
  9     ws: WebSocket;
            ~~~~~~~~~
  
  node_modules/websocket-as-promised/types/index.d.ts:21:25 - error TS2304: Cannot find name 'Event'.
  
  21     open: () => Promise<Event>;
                             ~~~~~
  
  node_modules/websocket-as-promised/types/index.d.ts:26:26 - error TS2304: Cannot find name 'CloseEvent'.
  
  26     close: () => Promise<CloseEvent>;
                              ~~~~~~~~~~
  
  node_modules/websocket-as-promised/types/options.d.ts:5:40 - error TS2304: Cannot find name 'WebSocket'.
  
  5     createWebSocket?: (url: string) => WebSocket;
                                           ~~~~~~~~~

richenlin avatar Dec 14 '21 11:12 richenlin