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

Type errors for AWS SDK 3.10.0 #10

Closed
alexbaileyuk opened this issue Mar 29, 2021 · 9 comments
Closed

Type errors for AWS SDK 3.10.0 #10

alexbaileyuk opened this issue Mar 29, 2021 · 9 comments

Comments

@alexbaileyuk
Copy link

alexbaileyuk commented Mar 29, 2021

I'm having some trouble with types. Using //@ts-ignore works but probably isn't solving the problem.

Example code:

import {mockClient} from 'aws-sdk-client-mock';
import {GetQueueAttributesCommand, GetQueueUrlCommand, SQSClient} from '@aws-sdk/client-sqs';
import {AssertQueueLength} from '../../../src/sqs/SQSChecks';

const sqsMock = mockClient(SQSClient);

beforeEach(() => {
    sqsMock.reset();
});

describe('AssertQueueLength', () => {
    it('Should return true when the approx. queue length matches the expected value.', async () => {
        sqsMock.on(GetQueueUrlCommand).resolves({
            QueueUrl: 'http://aws.com/queue'
        });

        sqsMock.on(GetQueueAttributesCommand).resolves({
            Attributes: {
                ApproximateNumberOfMessages: '1'
            }
        });

        expect(await AssertQueueLength('my-queue', 1)).toBeTruthy();
    });
});

Error thrown:

 FAIL  packages/checks/tests/units/sqs/SQSHelper.spec.ts
  ● Test suite failed to run

    packages/checks/tests/units/sqs/SQSHelper.spec.ts:6:28 - error TS2345: Argument of type 'typeof SQSClient' is not assignable to parameter of type 'InstanceOrClassType<Client<ServiceInputTypes, ServiceOutputTypes, any>>'.
      Type 'typeof SQSClient' is not assignable to type 'ClassType<Client<ServiceInputTypes, ServiceOutputTypes, any>>'.
        The types of 'prototype.middlewareStack.add' are incompatible between these types.
          Type '{ (middleware: import("/home/alex/dev/manage-alerts/node_modules/@aws-sdk/smithy-client/node_modules/@aws-sdk/types/dist/types/middleware").InitializeMiddleware<import("/home/alex/dev/manage-alerts/node_modules/@aws-sdk/client-sqs/dist/types/SQSClient").ServiceInputTypes, import("/home/alex/dev/man...' is not assignable to type '{ (middleware: import("/home/alex/dev/manage-alerts/node_modules/@aws-sdk/types/types/ts3.4/middleware").InitializeMiddleware<import("/home/alex/dev/manage-alerts/node_modules/@aws-sdk/client-sqs/dist/types/SQSClient").ServiceInputTypes, import("/home/alex/dev/manage-alerts/node_modules/@aws-sdk/cl...'.
            Types of parameters 'middleware' and 'middleware' are incompatible.
              Types of parameters 'context' and 'context' are incompatible.
                Type 'import("/home/alex/dev/manage-alerts/node_modules/@aws-sdk/smithy-client/node_modules/@aws-sdk/types/dist/types/middleware").HandlerExecutionContext' is not assignable to type 'import("/home/alex/dev/manage-alerts/node_modules/@aws-sdk/types/types/ts3.4/middleware").HandlerExecutionContext'.
                  Types of property 'userAgent' are incompatible.
                    Type 'import("/home/alex/dev/manage-alerts/node_modules/@aws-sdk/smithy-client/node_modules/@aws-sdk/types/dist/types/util").UserAgent' is not assignable to type 'import("/home/alex/dev/manage-alerts/node_modules/@aws-sdk/types/types/ts3.4/util").UserAgent'.
                      Type 'import("/home/alex/dev/manage-alerts/node_modules/@aws-sdk/smithy-client/node_modules/@aws-sdk/types/dist/types/util").UserAgentPair' is not assignable to type 'import("/home/alex/dev/manage-alerts/node_modules/@aws-sdk/types/types/ts3.4/util").UserAgentPair'.
                        Types of property 'length' are incompatible.
                          Type '4' is not assignable to type '2'.

    6 const sqsMock = mockClient(SQSClient);
                                 ~~~~~~~~~
    packages/checks/tests/units/sqs/SQSHelper.spec.ts:15:20 - error TS2345: Argument of type 'typeof GetQueueUrlCommand' is not assignable to parameter of type 'new (input: GetQueueUrlRequest) => AwsCommand<GetQueueUrlRequest, GetQueueUrlCommandOutput, any, any>'.
      Construct signature return types 'GetQueueUrlCommand' and 'AwsCommand<GetQueueUrlRequest, GetQueueUrlCommandOutput, any, any>' are incompatible.
        The types of 'middlewareStack.add' are incompatible between these types.
          Type '{ (middleware: import("/home/alex/dev/manage-alerts/node_modules/@aws-sdk/smithy-client/node_modules/@aws-sdk/types/dist/types/middleware").InitializeMiddleware<import("/home/alex/dev/manage-alerts/node_modules/@aws-sdk/client-sqs/dist/types/models/models_0").GetQueueUrlRequest, import("/home/alex/dev/me...' is not assignable to type '{ (middleware: import("/home/alex/dev/manage-alerts/node_modules/@aws-sdk/types/types/ts3.4/middleware").InitializeMiddleware<import("/home/alex/dev/manage-alerts/node_modules/@aws-sdk/client-sqs/dist/types/models/models_0").GetQueueUrlRequest, import("/home/alex/dev/manage-alerts/node_modules/@aws...'.
            Types of parameters 'middleware' and 'middleware' are incompatible.
              Types of parameters 'context' and 'context' are incompatible.
                Type 'import("/home/alex/dev/manage-alerts/node_modules/@aws-sdk/smithy-client/node_modules/@aws-sdk/types/dist/types/middleware").HandlerExecutionContext' is not assignable to type 'import("/home/alex/dev/manage-alerts/node_modules/@aws-sdk/types/types/ts3.4/middleware").HandlerExecutionContext'.

    15         sqsMock.on(GetQueueUrlCommand).resolves({
                          ~~~~~~~~~~~~~~~~~~
    packages/checks/tests/units/sqs/SQSHelper.spec.ts:20:20 - error TS2345: Argument of type 'typeof GetQueueAttributesCommand' is not assignable to parameter of type 'new (input: GetQueueAttributesRequest) => AwsCommand<GetQueueAttributesRequest, GetQueueAttributesCommandOutput, any, any>'.
      Construct signature return types 'GetQueueAttributesCommand' and 'AwsCommand<GetQueueAttributesRequest, GetQueueAttributesCommandOutput, any, any>' are incompatible.
        The types of 'middlewareStack.add' are incompatible between these types.
          Type '{ (middleware: import("/home/alex/dev/manage-alerts/node_modules/@aws-sdk/smithy-client/node_modules/@aws-sdk/types/dist/types/middleware").InitializeMiddleware<import("/home/alex/dev/manage-alerts/node_modules/@aws-sdk/client-sqs/dist/types/models/models_0").GetQueueAttributesRequest, import("/home/alex...' is not assignable to type '{ (middleware: import("/home/alex/dev/manage-alerts/node_modules/@aws-sdk/types/types/ts3.4/middleware").InitializeMiddleware<import("/home/alex/dev/manage-alerts/node_modules/@aws-sdk/client-sqs/dist/types/models/models_0").GetQueueAttributesRequest, import("/home/alex/dev/manage-alerts/node_modul...'.
            Types of parameters 'middleware' and 'middleware' are incompatible.
              Types of parameters 'context' and 'context' are incompatible.
                Type 'import("/home/alex/dev/manage-alerts/node_modules/@aws-sdk/smithy-client/node_modules/@aws-sdk/types/dist/types/middleware").HandlerExecutionContext' is not assignable to type 'import("/home/alex/dev/manage-alerts/node_modules/@aws-sdk/types/types/ts3.4/middleware").HandlerExecutionContext'.

    20         sqsMock.on(GetQueueAttributesCommand).resolves({
                          ~~~~~~~~~~~~~~~~~~~~~~~~~

If I add // @ts-ignore as below then all works as expected:

import {mockClient} from 'aws-sdk-client-mock';
import {GetQueueAttributesCommand, GetQueueAttributesResult, GetQueueUrlCommand, SQSClient} from '@aws-sdk/client-sqs';
import {AssertQueueLength} from '../../../src/sqs/SQSChecks';

// @ts-ignore
const sqsMock = mockClient(SQSClient);

beforeEach(() => {
    sqsMock.reset();
});

describe('AssertQueueLength', () => {
    it('Should return true when the approx. queue length matches the expected value.', async () => {
        // @ts-ignore
        sqsMock.on(GetQueueUrlCommand).resolves({
            QueueUrl: 'http://aws.com/queue'
        });

        // @ts-ignore
        sqsMock.on(GetQueueAttributesCommand).resolves({
            Attributes: {
                ApproximateNumberOfMessages: '1'
            }
        });

        expect(await AssertQueueLength('my-queue', 1)).toBeTruthy();
    });
});

Packages:

  "dependencies": {
    "@aws-sdk/client-sqs": "^3.10.0"
  },
  "devDependencies": {
    "aws-sdk-client-mock": "^0.2.0"
  }

ts-config:

{
  "compilerOptions": {
    "target": "ES2020",
    "module": "commonjs",
    "lib": ["es2020"]
  },
  "include": [
    "packages/*"
  ]
}

Any help would be appreciated.

@m-radzikowski
Copy link
Owner

Hey, I see the types in AWS SDK changed somewhere between 3.4.1 (when I last tested it) and 3.10.0 (the current one). I will work on the fix. Thanks for the report!

@m-radzikowski m-radzikowski added the bug Something isn't working label Mar 30, 2021
@m-radzikowski m-radzikowski changed the title Type errors Type errors for AWS SDK 3.10.0 Mar 30, 2021
@m-radzikowski
Copy link
Owner

Nope, ignore my previous message, I was wrong.

If you have a project with only @aws-sdk/client-sqs v3.10.0, then everything works.

But if you have multiple AWS packages in dependencies in different versions, then you will end up @aws-sdk/types dependency on the top level (if using yarn) in one of those versions. With npm it will be similar. So if you have @aws-sdk/client-sqs v3.10.0 and also for example @aws-sdk/client-dynamodb v3.5.0, then types will be incompatible for one of those.

Best what you can do is to use the same versions for all the AWS SDK dependencies.

Another solution would be to specify the @aws-sdk/types version explicitly, in the same version as the SDK you want to test. But then you will be able to write tests only for SDK libraries in the same version.

Does it solve your problem?

@alexbaileyuk
Copy link
Author

alexbaileyuk commented Mar 31, 2021

It didn't but it got me thinking about the types. Turns out that I didn't have the @aws-sdk/types package at all and that was causing issues. Adding that as a dev dependency fixed the problem.

Thanks! Great package by the way! Super simple to use!

@m-radzikowski
Copy link
Owner

The @aws-sdk/types is a dependency of all AWS SDK clients, and it should be in the same version as the SDK client. Here is seems that for some reason a different version was installed - maybe some other dependency requested it? Anyway, good that it helped you solve the issue, please reopen in case of further problems with types.

Thanks! Great package by the way! Super simple to use!

Thank you, good to hear it!

@m-radzikowski m-radzikowski removed the bug Something isn't working label Mar 31, 2021
@RichardBradley
Copy link
Contributor

Best what you can do is to use the same versions for all the AWS SDK dependencies.

Another solution would be to specify the @aws-sdk/types version explicitly

I had this issue -- it seems that I had multiple incompatible versions of '@aws-sdk/types' installed, although I couldn't figure out why.

I spent quite a while trying to ensure that I had the same exact version installed of all my aws sdk clients, but it still remained.

In the end I installed @aws-sdk/types explicitly at the same version as my aws sdk clients, which resolved this.

(Just a note in case anyone else has the same issue)

@Horlando-Leao
Copy link

For me it worked by installing @aws-sdk/types in the same version of sdk packages

@florianakos
Copy link

Anyone knows how could I resolve this issue when tsyringe tries to work with DynamoDBClient?

src/sensor-registry/event-publisher/handle.ts:41:28 - error TS2769: No overload matches this call.
  The last overload gave the following error.
    Argument of type 'typeof DynamoDBClient' is not assignable to parameter of type 'InjectionToken<DynamoDBClient>'.
      Type 'typeof DynamoDBClient' is not assignable to type 'constructor<DynamoDBClient>'.
        Types of construct signatures are incompatible.
          Type 'new (...[configuration]: [] | [DynamoDBClientConfig]) => DynamoDBClient' is not assignable to type 'new (...args: any[]) => DynamoDBClient'.
            Types of parameters '__0' and 'args' are incompatible.
              Type 'any[]' is not assignable to type '[] | [DynamoDBClientConfig]'.
                Type 'any[]' is not assignable to type '[DynamoDBClientConfig]'.
                  Target requires 1 element(s) but source may have fewer.

41         container.register(DynamoDBClient, {
                              ~~~~~~~~~~~~~~

  node_modules/tsyringe/dist/typings/types/dependency-container.d.ts:31:5
    31     register<T>(token: InjectionToken<T>, provider: constructor<T>, options?: RegistrationOptions): DependencyContainer;
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The last overload is declared here.


@kjahan22
Copy link

kjahan22 commented Nov 27, 2023

Could you get a solution for this error? @florianakos ? seeing the same error after updating @aws-sdk/client-dynamodb to 3.445.0

@hxtree
Copy link

hxtree commented Dec 6, 2023

I experience similar with CognitoIdentityProviderClient. It was saying command was incompatible type using the latest in typescript.

const command = new   SignUpCommand({
  ClientId:  await this.fetchUserPoolClientId(),
  Username: username,
  Password: password,
  UserAttributes: [
    { Name: 'email', Value: email },
    { Name: 'nickname', Value: nickname },
    { Name: 'phone_number', Value: phone_number },
],
});

await this.cognitoClient.send(command);

After downgrading '@aws-sdk/client-cognito-identity-provider' to 3.10.0 it no longer failed for type errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants