Apollo-client: Typescript: Argument of type '(ApolloLink | RestLink)[]' is not assignable to parameter of type 'ApolloLink[]'. Type 'ApolloLink | RestLink' is not assignable to type 'ApolloLink'.

Created on 27 Feb 2018  路  6Comments  路  Source: apollographql/apollo-client

The project was working just fine until recent got this error out of nowhere. Can't figure out why.

screen shot 2018-02-26 at 10 36 11 pm
screen shot 2018-02-26 at 10 36 04 pm

Most helpful comment

In my case I was using yarn and some sub dependency was not using the latest apollo-link version.

Forcing my project to use the latest apollo-link resolved it.

All 6 comments

I'm seeing the same error, although I use this:

  const link = graphqlHost
    ? new HttpLink({
        uri: graphqlHost,
        fetch,
      })
    : new SchemaLink({ schema, context: createContext(req, apiHost) })

  const client = new ApolloClient({ ssrMode: true, link, cache })

In my case I was using yarn and some sub dependency was not using the latest apollo-link version.

Forcing my project to use the latest apollo-link resolved it.

Similar thing here:

screen shot 2018-03-08 at 09 04 31

lib/initApollo.ts(16,27): error TS2345: Argument of type '{ connectToDevTools: boolean; ssrMode: boolean; link: HttpLink; cache: InMemoryCache; }' is not assignable to parameter of type 'ApolloClientOptions<NormalizedCacheObject>'.
  Types of property 'link' are incompatible.
    Type 'HttpLink' is not assignable to type 'ApolloLink'.
      Types of property 'split' are incompatible.
        Type '(test: (op: Operation) => boolean, left: ApolloLink | RequestHandler, right?: ApolloLink | Reques...' is not assignable to type '(test: (op: Operation) => boolean, left: ApolloLink | RequestHandler, right?: ApolloLink | Reques...'. Two different types with this name exist, but they are unrelated.
          Types of parameters 'left' and 'left' are incompatible.
            Type 'ApolloLink | RequestHandler' is not assignable to type 'ApolloLink | RequestHandler'. Two different types with this name exist, but they are unrelated.
              Type 'ApolloLink' is not assignable to type 'ApolloLink | RequestHandler'.
                Type 'ApolloLink' is not assignable to type 'RequestHandler'.
                  Type 'ApolloLink' provides no match for the signature '(operation: Operation, forward?: NextLink): Observable<any>'.

Temp fix:

screen shot 2018-03-08 at 09 04 45

__UPD:__ got this healed by yarn upgrade 馃

Just wanted say I managed to fix this by installing apollo-link. Seems the other modules used this new module (perhaps as a peer-dependency).

Sounds like this has been fixed - closing, thanks!

If you are using apollo v3 import onError as
import { onError } from '@apollo/client/link/error';

Was this page helpful?
0 / 5 - 0 ratings