Skip to content

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

@m-radzikowski

Description

@m-radzikowski

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:

  • make sure all your @aws-sdk/* packages point to the same version,
  • remove all @aws-sdk/* packages from package.json, run npm install / pnpm install / yarn install, restore @aws-sdk/* packages in package.json, and run install again,
  • add @smithy/types to your dev dependencies in the latest version,
  • force using single @smithy/types version with npm overrides, pnpm overrides, or yarn resolutions,
  • if nothing else helped, open an issue including the output of npm ls @smithy/types / pnpm why @smithy/types / yarn why @smithy/types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions