urql-graphql / urql

The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
https://urql.dev/goto/docs
MIT License
8.6k stars 448 forks source link

Using 6.1.5-canary throws `Type '(Exchange | Exchange)[]' is not assignable to type 'Exchange[]'.` #3321

Closed frederikhors closed 1 year ago

frederikhors commented 1 year ago

Describe the bug

Trying to upgrade my @urql dependencies using exchange-graphcache@6.1.5 I found a TS error:

Type '(Exchange | Exchange)[]' is not assignable to type 'Exchange[]'.
  Type 'Exchange | Exchange' is not assignable to type 'Exchange'.
    Type 'import("c:/prj/node_modules/@urql/exchange-graphcache/node_modules/@urql/core/dist/urql-core-chunk").Exchange' is not assignable to type 'import("c:/prj/node_modules/@urql/core/dist/urql-core-chunk").Exchange'.
      Types of parameters 'input' and 'input' are incompatible.
        Type 'import("c:/prj/node_modules/@urql/core/dist/urql-core-chunk").ExchangeInput' is not assignable to type 'import("c:/prj/node_modules/@urql/exchange-graphcache/node_modules/@urql/core/dist/urql-core-chunk").ExchangeInput'.
          The types of 'client.operations$' are incompatible between these types.
            Type 'import("c:/prj/node_modules/wonka/dist/wonka").Source<import("c:/prj/node_modules/@urql/core/dist/urql-core-chunk").Operation<any, import("c:/prj/node_modules/@urql/core/dist/urql-core-chunk").AnyVariables>>' is not assignable to type 'import("c:/prj/node_modules/wonka/dist/wonka").Source<import("c:/prj/node_modules/@urql/exchange-graphcache/node_modules/@urql/core/dist/urql-core-chunk").Operation<any, import("c:/prj/node_modules/@urql/exchange-graphcache/node_modules/@urql/core/dis...'.
              Type 'import("c:/prj/node_modules/@urql/core/dist/urql-core-chunk").Operation<any, import("c:/prj/node_modules/@urql/core/dist/urql-core-chunk").AnyVariables>' is not assignable to type 'import("c:/prj/node_modules/@urql/exchange-graphcache/node_modules/@urql/core/dist/urql-core-chunk").Operation<any, import("c:/prj/node_modules/@urql/exchange-graphcache/node_modules/@urql/core/dist/urql-core-chunk").AnyVariables>'.
                The types of 'context._instance' are incompatible between these types.
                  Type 'import("c:/prj/node_modules/@urql/core/dist/urql-core-chunk").OperationInstance | undefined' is not assignable to type 'import("c:/prj/node_modules/@urql/exchange-graphcache/node_modules/@urql/core/dist/urql-core-chunk").OperationInstance | undefined'.
                    Type 'OperationInstance' is not assignable to type 'OperationInstance | undefined'.
                      Type 'import("c:/prj/node_modules/@urql/core/dist/urql-core-chunk").OperationInstance' is not assignable to type 'import("c:/prj/node_modules/@urql/exchange-graphcache/node_modules/@urql/core/dist/urql-core-chunk").OperationInstance'.
                        Type 'OperationInstance' is not assignable to type '{ readonly _opaque: unique symbol; }'.
                          Types of property '_opaque' are incompatible.
                            Type 'typeof _opaque' is not assignable to type 'typeof _opaque'. Two different types with this name exist, but they are unrelated.ts(2322)
urql-core-chunk.d.ts(88, 5): The expected type comes from property 'exchanges' which is declared here on type 'ClientOptions'

when using:

const exchanges = [
  offlineExchange({ // Because of this <-------------------------
    resolvers,
    schema,
    storage,
    updates
  }),
  retryExchange(retryOptions),
  persistedExchange(),
  fetchExchange
];

const client = createClient({
  url,
  fetchOptions,
  exchanges, // Here the error <-------------------------
});

Validations

kitten commented 1 year ago

This is indicated in the description as a duplicate installation of @urql/core

There's instructions and other issues around for this but let me know if you'd like me to copy them here

frederikhors commented 1 year ago

I'm using npm dedupe after npm install. What should I do more?

kitten commented 1 year ago

Ah, you're using the canary of Graphcache. That will be using the canary of @urql/core. List out which one is installed and use that version throughout, or ignore the error, since it's just a type error