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
790 stars 38 forks source link

not compatible with "@aws-sdk/xxx": "3.451.0" #193

Closed chejimmy closed 9 months ago

chejimmy commented 10 months ago

Checklist

Bug description

Since upgrading @aws-sdk/* to 3.451.0, I'm getting the type issue below using a client. For example, for DynamoDBClient:

Argument of type 'typeof DynamoDBClient' is not assignable to parameter of type 'InstanceOrClassType<Client<ServiceInputTypes, MetadataBearer, SmithyResolvedConfiguration<HttpHandlerOptions>>>'.
  Type 'typeof DynamoDBClient' is not assignable to type 'ClassType<Client<ServiceInputTypes, MetadataBearer, SmithyResolvedConfiguration<HttpHandlerOptions>>>'.
    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.
          Type 'MiddlewareStack<InputType, OutputType>' is not assignable to type 'MiddlewareStack<InputType, ServiceOutputTypes>'.
            Types of property 'addRelativeTo' are incompatible.
              Type '(middleware: MiddlewareType<InputType, OutputType>, options: RelativeMiddlewareOptions) => void' is not assignable to type '(middleware: MiddlewareType<InputType, ServiceOutputTypes>, options: RelativeMiddlewareOptions) => void'.
                Types of parameters 'middleware' and 'middleware' are incompatible.
                  Type 'MiddlewareType<InputType, ServiceOutputTypes>' is not assignable to type 'MiddlewareType<InputType, OutputType>'.
                    Type 'InitializeMiddleware<InputType, ServiceOutputTypes>' is not assignable to type 'MiddlewareType<InputType, OutputType>'.
                      Type 'InitializeMiddleware<InputType, ServiceOutputTypes>' is not assignable to type 'InitializeMiddleware<InputType, OutputType>'.
                        Call signature return types 'InitializeHandler<InputType, ServiceOutputTypes>' and 'InitializeHandler<InputType, OutputType>' are incompatible.
                          Type 'Promise<InitializeHandlerOutput<ServiceOutputTypes>>' is not assignable to type 'Promise<InitializeHandlerOutput<OutputType>>'.
                            Type 'InitializeHandlerOutput<ServiceOutputTypes>' is not assignable to type 'InitializeHandlerOutput<OutputType>'.
                              Types of property 'output' are incompatible.
                                Type 'ServiceOutputTypes' is not assignable to type 'OutputType'.
                                  'ServiceOutputTypes' is assignable to the constraint of type 'OutputType', but 'OutputType' could be instantiated with a different subtype of constraint 'MetadataBearer'.
                                    Type 'BatchExecuteStatementCommandOutput' is not assignable to type 'OutputType'.
                                      'BatchExecuteStatementCommandOutput' is assignable to the constraint of type 'OutputType', but 'OutputType' could be instantiated with a different subtype of constraint 'MetadataBearer'.

The issue doesn't happen when using @aws-sdk/*@3.450.0. I believe it may be to do with AWS updating Smithy

Reproduction

import { DynamoDBClient } from '@aws-sdk/client-dynamodb';

const ddbMock = mockClient(DynamoDBClient);

Environment

chejimmy commented 10 months ago

Found another issue with similar bug behavior https://github.com/m-radzikowski/aws-sdk-client-mock/issues/185 however, the other issue is with v3.378.0 and this one with v3.451.0

AminFazlMondo commented 10 months ago

Is there any solution for this bug?

AminFazlMondo commented 9 months ago

Is there any solution for this bug?

It is fixed for me now with the later versions. Thanks

dannyfranca commented 9 months ago

I have sent a PR to fix this issue for the next release: https://github.com/m-radzikowski/aws-sdk-client-mock/pull/196

m-radzikowski commented 9 months ago

I did not get any type compatibility issues on the clean install of @aws-sdk/* packages in v3.451.0. The issue is, most likely, @smithy/types installed in multiple versions, which happens sometimes if you add/bump @aws-sdk/* packages. See the caveats section in README for solution details. If you still have problem, please reopen the issue including the content of your package.json and output of npm ls @smithy/types / pnpm why @smithy/types / yarn why @smithy/types.