awslabs / aws-mobile-appsync-sdk-js

JavaScript library files for Offline, Sync, Sigv4. includes support for React Native
Apache License 2.0
920 stars 266 forks source link

Typescript error while compiling aws-appsync #583

Open JohnAtFenestra opened 4 years ago

JohnAtFenestra commented 4 years ago

Attempting to compile the current code base to get a better handle on how everything really works for a major project. After installing typescript

Ubuntu 20.04.1 LTS x86_64
$ tsc --version
Version 3.9.7
$ node --version
v12.16.3

I ran npm install at packages/aws-appsync and got the following error:

$ npm install

> aws-appsync@4.0.0 prepare aws-mobile-appsync-sdk-js/packages/aws-appsync
> tsc

src/link/offline-link.ts:420:17 - error TS2698: Spread types may only be created from object types.

420                 ...entries,
                    ~~~~~~~~~~

Found 1 error.

npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! aws-appsync@4.0.0 prepare: `tsc`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the aws-appsync@4.0.0 prepare script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/john/.npm/_logs/2020-08-12T14_44_07_060Z-debug.log

A search on Google turned up that this was an old error purportedly fixed in TypeScript Version 3.2. I'm not sure which version of TypeScript the developers are using, but it appears that the code will not compile under the most current.

UPDATE:

Doing a bit of exploration, it seems the problem can be easily fixed by adding the type declaration:

      const entries: Object = Object.values(ids).reduce(
        (acc: { [key: string]: string }, id: string) => ((acc[id] = null), acc),
        {}
      )

      return {
        ...state,
        ...entries,
      }

However, that leaves my base question: How is this even compiling, leastwise passing unit tests?