m-radzikowski / aws-sdk-client-mock

AWS JavaScript SDK v3 mocks for easy unit testing. 🖋️ Typed 🔬 Tested 📄 Documented 🛠️ Maintained
https://m-radzikowski.github.io/aws-sdk-client-mock/
MIT License
812 stars 40 forks source link

Solution to types not compatible with @aws-sdk/* version 3.xxx.x #197

Open m-radzikowski opened 11 months ago

m-radzikowski commented 11 months ago

After upgrading @aws-sdk/* package(s) to a newer version, the mockClient() function throws type errors similar to this:

TS2345: Argument of type 'typeof DynamoDBDocumentClient' is not assignable to parameter of type 'InstanceOrClassType<Client<ServiceInputTypes, MetadataBearer, any>>'.
  Type 'typeof DynamoDBDocumentClient' is not assignable to type 'ClassType<Client<ServiceInputTypes, MetadataBearer, any>>'.
    The types of 'prototype.middlewareStack.concat' are incompatible between these types.
      Type '<InputType extends ServiceInputTypes, OutputType extends ServiceOutputTypes>(from: MiddlewareStack<InputType, OutputType>) => MiddlewareStack<...>' is not assignable to type '<InputType extends ServiceInputTypes, OutputType extends MetadataBearer>(from: MiddlewareStack<InputType, OutputType>) => MiddlewareStack<InputType, OutputType>'.
        Types of parameters 'from' and 'from' are incompatible.
          Property 'identify' is missing in type 'MiddlewareStack<InputType, OutputType>' but required in type 'MiddlewareStack<InputType, ServiceOutputTypes>'.

In 99% of cases, this is not a problem with type incompatibility between @aws-sdk/* and aws-sdk-client-mock, but a resolut of having multiple versions of @smithy/types package installed.

Follow those steps to solve it

Go through the steps until one works:

Run npm ls @smithy/types / pnpm why @smithy/types / yarn why @smithy/types and check if you have more than one version of the package installed.

Go through the steps until one works: