aws-sdk-client-mock icon indicating copy to clipboard operation
aws-sdk-client-mock copied to clipboard

Doesn't run with TypeScript 4.8.2

Open frvi opened this issue 2 years ago • 4 comments

Checklist

  • [x] I have read Caveats documentation and didn't find a solution for this problem there.

Bug description

TypeError: Cannot read properties of undefined (reading 'kind')
    at getTypeFromTypeNodeWorker (/home/runner/work/backend-core-services/backend-core-services/services/backoffice-api/node_modules/typescript/lib/tsc.js:53060:26)
    at getTypeFromTypeNode (/home/runner/work/backend-core-services/backend-core-services/services/backoffice-api/node_modules/typescript/lib/tsc.js:53057:49)
    at getEffectiveTypeArgumentAtIndex (/home/runner/work/backend-core-services/backend-core-services/services/backoffice-api/node_modules/typescript/lib/tsc.js:68314:24)
    at Array.<anonymous> (/home/runner/work/backend-core-services/backend-core-services/services/backoffice-api/node_modules/typescript/lib/tsc.js:50294:52)
    at getMappedType (/home/runner/work/backend-core-services/backend-core-services/services/backoffice-api/node_modules/typescript/lib/tsc.js:53203:46)
    at instantiateTypeWorker (/home/runner/work/backend-core-services/backend-core-services/services/backoffice-api/node_modules/typescript/lib/tsc.js:53516:24)
    at instantiateTypeWithAlias (/home/runner/work/backend-core-services/backend-core-services/services/backoffice-api/node_modules/typescript/lib/tsc.js:53509:26)
    at instantiateType (/home/runner/work/backend-core-services/backend-core-services/services/backoffice-api/node_modules/typescript/lib/tsc.js:53495:37)
    at _loop_[15](https://github.com/doors-live/backend-core-services/runs/8193121746?check_suite_focus=true#step:8:16) (/home/runner/work/backend-core-services/backend-core-services/services/backoffice-api/node_modules/typescript/lib/tsc.js:50296:58)
    at getInferredTypeParameterConstraint (/home/runner/work/backend-core-services/backend-core-services/services/backoffice-api/node_modules/typescript/lib/tsc.js:50327:[21](https://github.com/doors-live/backend-core-services/runs/8193121746?check_suite_focus=true#step:8:22))

Reproduction

Bump TypeScript dependency to 4.8.2, and try to run the tests

Environment

  • Node version: v18.4.0
  • Testing lib and version:
  • Typescript version: 4.8.2
  • AWS SDK v3 Client mock version: 2.0.0
  • AWS JS SDK libs and versions:

frvi avatar Sep 07 '22 11:09 frvi

Facing the same issue currently.

Based on a likely related issue reported for TypeScript this may originate in the AwsClientStub, but I'm not remotely experienced enough in TS to provide any suggestions for a fix

mkrei avatar Sep 07 '22 19:09 mkrei

I managed to solve it using a previous version of TS

gastonestol avatar Sep 08 '22 09:09 gastonestol

I'm on vacation for the next 2 weeks, so I won't be able to work on this soon. But I can review a PR if someone creates a fix.

m-radzikowski avatar Sep 08 '22 10:09 m-radzikowski

After having another look and playing with the code a bit, it looks like my initial suspicion was wrong. The offending part of the code is not the AwsClientBehavior type, but rather Behavior::commandCalls. If you tweak the tsconfig to only build awsClientStub.ts, it will throw with the mentioned error by default, but succeed if Behavior::commandCalls is commented out.

Maybe someone can make use of this starter for an actual fix

mkrei avatar Sep 08 '22 14:09 mkrei

Like @mkrei mentioned, this happened if you used Behavior::commandCalls function and was caused by an issue in TypeScript. It was solved in TypeScript v4.8.4, so bumping the TS version should solve the problem.

m-radzikowski avatar Oct 09 '22 16:10 m-radzikowski