Apollo-client: building client errors: ERROR in node_modules/apollo-utilities/lib/util/mergeDeep.d.ts(2,52): error TS2370: A rest parameter must be of an array type.

Created on 18 Mar 2019  路  10Comments  路  Source: apollographql/apollo-client

we're trying to build our angular app in docker but apollo errors: ERROR in node_modules/apollo-utilities/lib/util/mergeDeep.d.ts(2,52): error TS2370: A rest parameter must be of an array type.
we've already updated all our dependencies to the latest version to try and fix this but no luck.
Any ideas would be most welcome.

Intended outcome:

building the client in docker

Actual outcome:

ERROR in node_modules/apollo-utilities/lib/util/mergeDeep.d.ts(2,52): error TS2370: A rest parameter must be of an array type.

Versions
System: OS: macOS Sierra 10.12.6 Binaries: Node: 8.11.3 - /usr/local/bin/node Yarn: 1.9.4 - /usr/local/bin/yarn npm: 6.5.0 - /usr/local/bin/npm Browsers: Chrome: 72.0.3626.121 Firefox: 65.0.1 Safari: 12.0.3

package.json:

{
  "name": "client",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve --port 4200 --host 0.0.0.0 --poll 500 --proxy-config proxy.config.json",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "update:schema": "apollo schema:download --endpoint http://0.0.0.0:8000/graphql ./src/app/graphql/schema.json",
    "update:types": "apollo codegen:generate --schema ./src/app/graphql/schema.json --target=typescript"
  },
  "apollo": {
    "schemas": {
      "api": {
        "schema": "src/app/graphql/schema.graphql",
        "endpoint": "http://0.0.0.0:8000/graphql"
      }
    },
    "queries": [
      {
        "schema": "api",
        "includes": [
          "**/*.ts"
        ],
        "excludes": [ "node_modules/**"
        ]
      }
    ]
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^7.2.9",
    "@angular/cdk": "^7.3.4",
    "@angular/common": "^7.2.9",
    "@angular/compiler": "^7.2.9",
    "@angular/core": "^7.2.9",
    "@angular/flex-layout": "6.0.0-beta.18",
    "@angular/forms": "^7.2.9",
    "@angular/http": "^7.2.9",
    "@angular/material": "^7.3.4",
    "@angular/platform-browser": "^7.2.9",
    "@angular/platform-browser-dynamic": "^7.2.9",
    "@angular/router": "^7.2.9",
    "apollo-angular": "^1.5.0",
    "core-js": "^2.6.5",
    "rxjs": "^6.4.0",
    "zone.js": "~0.8.29",
    "apollo-angular-link-http": "^1.5.0",
    "apollo-link": "^1.2.11",
    "apollo-client": "^2.5.1",
    "apollo-cache-inmemory": "^1.5.1",
    "graphql-tag": "^2.10.1",
    "graphql": "^14.1.1"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.13.6",
    "@angular/cli": "~7.3.6",
    "@angular/compiler-cli": "^7.2.9",
    "@angular/language-service": "^7.2.9",
    "@types/jasmine": "~3.3.10",
    "@types/jasminewd2": "~2.0.6",
    "@types/node": "~11.11.3",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~3.3.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.0.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.5",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.0",
    "protractor": "~5.4.2",
    "ts-node": "~8.0.3",
    "tsc-watch": "^2.1.2",
    "tslint": "~5.14.0",
    "typescript": "^3.3.3333"
  }
}

Most helpful comment

I can't test it right now but downgrading apollo-utilities to 1.0.22 might work.
let me know how it goes if you give it a try.

All 10 comments

Have the same issue.
I'm using angular 6.1.10 and typescript 2.9.0

I can't test it right now but downgrading apollo-utilities to 1.0.22 might work.
let me know how it goes if you give it a try.

I can't test it right now but downgrading apollo-utilities to 1.0.22 might work.
let me know how it goes if you give it a try.

Yep, I added [email protected] as a dependency and it works ( for someone who faced the same issue, don't forget to clear node_modules with previous apollo-utilities).
Thanks a lot!

Likely duplicate of https://github.com/apollographql/apollo-client/issues/4506.

tl;dr If you can update the typescript package to at least 3.0, this error should go away, per https://github.com/apollographql/apollo-client/issues/4501#issuecomment-468001034. Since the original poster seems to be using [email protected], I would ask that they double-check there are no other copies of the typescript package in use.

In case you think this must be an Apollo Client problem and not a TypeScript problem (or an Angular-and-TypeScript) problem, here's the only occurrence of a ...rest parameter in mergeDeep.ts:

export function mergeDeep<T extends any[]>(
  ...sources: T
): TupleToIntersection<T> {
  return mergeDeepArray(sources);
}

I would love to understand how T is not considered an array type here.

You can downgrade apollo-utilities if you like, but you might consider upgrading to a version of typescript that understands its own type system (if you're knowingly still using typescript@2), instead.

I get the warning even though the file mergeDeep.d.ts doesnt even exist in apollo-utilities.

@benjamn I assume any is far to broad for typescript to understand its an array. I had a similar issue here

But any[] is definitely an array, no?

seems typescript not that smart

try use:

export function mergeDeep<T>(
  ...sources: T[]
): TupleToIntersection<T[]> {
  return mergeDeepArray(sources);
}

@NateScarlet 's suggestion got me in the right place. I changed T to be an array for line 2.

export declare function mergeDeep<T extends any[]>(
  ...sources: T[]
): TupleToIntersection<T>;

As mentioned in https://github.com/apollographql/apollo-client/issues/4594#issuecomment-474010788, this is not an Apollo Client issue. Thanks!

Was this page helpful?
0 / 5 - 0 ratings