Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: build in typescript Found 4 errors. #42

Open
richenlin opened this issue Dec 14, 2021 · 0 comments
Open

bug: build in typescript Found 4 errors. #42

richenlin opened this issue Dec 14, 2021 · 0 comments

Comments

@richenlin
Copy link

richenlin commented Dec 14, 2021

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;
                                           ~~~~~~~~~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant