Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK updated to use @smithy types and protocol http causing type errors when using mock clients #162

Closed
1 task done
stitch-rich opened this issue May 25, 2023 · 8 comments
Labels
bug Something isn't working waiting for reply

Comments

@stitch-rich
Copy link

stitch-rich commented May 25, 2023

Checklist

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

Bug description

Following this change to the AWS SDK aws/aws-sdk-js-v3#4722 the mock clients throw a number of TS errors when ever mocks are created. This change was introduced in the 3.355.0 release https://github.com/aws/aws-sdk-js-v3/releases/tag/v3.335.0

I have tried this with SNS, Secrets manager and Cognito Identity provider with the same result.

Reproduction

import { mockClient } from 'aws-sdk-client-mock';
import 'aws-sdk-client-mock-jest';
import { CognitoIdentityProviderClient } from '@aws-sdk/client-cognito-identity-provider';

const cognitoMock = mockClient(CognitoIdentityProviderClient); // This will show a type error 

Environment

  • Node version: 18.16.0
  • Testing lib and version: Jest 29.5.0
  • Typescript version: 5.04
  • AWS SDK v3 Client mock version: 2.1.1
  • AWS JS SDK libs and versions:
    • @aws-sdk/client-cognito-identity-provider 3.338.0
    • @aws-sdk/client-secrets-manager 3.338.0
@stitch-rich stitch-rich added the bug Something isn't working label May 25, 2023
@DDachev-Allaine
Copy link

DDachev-Allaine commented May 26, 2023

I have the same issue.
Error when using mockClient(DynamoDBClient);

Argument of type 'typeof DynamoDBClient' is not assignable to parameter of type 'InstanceOrClassType<Client<ServiceInputTypes, MetadataBearer, any>>'. Type 'typeof DynamoDBClient' 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. 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'.

And this it the error when using expect(dynamoDBMock).toReceiveCommandTimes(QueryCommand, 1);

Argument of type 'typeof QueryCommand' is not assignable to parameter of type 'new (input: QueryCommandInput) => AwsCommand<QueryCommandInput, MetadataBearer>'. Types of construct signatures are incompatible. Type 'new (input: QueryCommandInput) => QueryCommand' is not assignable to type 'new (input: QueryCommandInput) => AwsCommand<QueryCommandInput, MetadataBearer>'. Type 'QueryCommand' is not assignable to type 'AwsCommand<QueryCommandInput, MetadataBearer>'.

  • Node version: 18.12.0
  • Testing lib and version: Jest 29.5.0
  • Typescript version: 5.0.3
  • AWS SDK v3 Client mock version: 2.1.1
  • AWS JS SDK libs and versions:
    • @aws-sdk/client-dynamodb: 3.338.0
    • @aws-sdk/client-s3: 3.338.0

@m-radzikowski
Copy link
Owner

Hey,
I can't reproduce it. I get no errors with SDK version 3.338.0 or 3.341.0 (the latest one at the moment).

Please make extra sure that all AWS SDK libs are in the same version. You can also run yarn why @aws-sdk/types (or similar for npm and pnpm) and check if there is more than 1 version of this package installed.

If the problem persists, please create a repo with reproduction and I will take a look.

@DDachev-Allaine
Copy link

DDachev-Allaine commented May 29, 2023

@m-radzikowski At what version is your @aws-sdk/types? I noticed the problem on my side occurred with versions above 3.272.0

@m-radzikowski
Copy link
Owner

@DDachev-Allaine I've tested this with @aws-sdk/types v3.338.0 and v3.341.0, just like other deps.

Again, if you want me to look at this, provide a reproduction.

@gmol27
Copy link

gmol27 commented May 31, 2023

In case this helps, I was getting the same errors using v3.342.0 (latest as of writing this comment), but resolved by explicitly adding @aws-sdk/types (matching version) to my dependencies.

@cchawn
Copy link

cchawn commented May 31, 2023

Was seeing a similar issue — making sure that all of our @aws-sdk/* dependencies were on the same version (latest 3.342.0) resolved it for me! ✅

@ThomSMG
Copy link

ThomSMG commented May 31, 2023

I still have the problem even with the same pinned down version of aws-sdk-v3 client libs and @aws-sdk/types.

=> nevermind. Good old delete of node_modules and yarn.lock and re-install solved it.

Screenshot 2023-05-31 at 23 38 24 Screenshot 2023-05-31 at 23 40 09

Node version: 18.16.0
Typescript version: 5.0.4
AWS SDK v3 Client mock version: 2.1.1
AWS JS SDK libs and versions:
@aws-sdk/client-lambda: 3.342.0
@aws-sdk/types: 3.342.0

@m-radzikowski
Copy link
Owner

I've added a warning about this higher in the README.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working waiting for reply
Projects
None yet
Development

No branches or pull requests

6 participants