1
"@apollo/client": "^3.0.2"
"@types/node": "^14.0.20",
"@types/react": "^16.9.49",
"typescript": "^4.0.3"

So I'm getting the above mentioned error when attempting to convert a file to typescript on the following code:

lib/withData.ts

  import { WebSocketLink } from '@apollo/client/link/ws';

  const wsLink = isBrowser ? new WebSocketLink({
    uri: process.env.NODE_ENV === 'development' ? endpointWS : prodEndpointWS,
    options: {
      reconnect: true,
      lazy: true
    }
  }) : null;

  if (wsLink) { 
    wsLink.subscriptionClient.on("connecting", () => {
      console.log("connecting");
    });
    
    wsLink.subscriptionClient.on("connected", () => {
      console.log("connected");
    });
    
    wsLink.subscriptionClient.on("reconnecting", () => {
      console.log("reconnecting");
    });
    
    wsLink.subscriptionClient.on("reconnected", () => {
      console.log("reconnected");
    });
    
    wsLink.subscriptionClient.on("disconnected", () => {
      console.log("disconnected");
    });
    
    wsLink.subscriptionClient.maxConnectTimeGenerator.duration = () =>
      wsLink.subscriptionClient.maxConnectTimeGenerator.max;
  }

How do I resolve this? My partial repo is located here: https://github.com/TheoMer/next_apollo

TheoG
  • 1,498
  • 4
  • 30
  • 54
  • 1
    The author of `WebSocketLink` decided to mark that property as `private` using the TS `private` keyword, preventing your from using it without a TS error. The `private` modifier has no effect at runtime and purely impacts static checking. The only practical way to overcome this is to suppress the error using various means such as type assertions. However, the use of `private` may convey the author's intent and you should think twice before using that member. – Aluan Haddad Sep 24 '20 at 08:12

1 Answers1

2

I resolved this by declaring wsLink as:

let wsLink: any;
TheoG
  • 1,498
  • 4
  • 30
  • 54