smithy-lang / smithy-typescript

Smithy code generators for TypeScript. (in development)
Apache License 2.0
228 stars 85 forks source link

TypeScript error for seemingly legitimate use of the SDK. #816

Closed richgarner-nsw-gov closed 9 months ago

richgarner-nsw-gov commented 1 year ago

When I try to use the SendMessageBatchCommand command in the send function of the SQS client I get this type error.

Example code:

import {
  SQSClient,
  SendMessageBatchCommand,
  SendMessageBatchCommandOutput,
} from "@aws-sdk/client-sqs";

export const sqsClient = new SQSClient({});

...

    const command = new SendMessageBatchCommand({
        QueueUrl: "QUEUE_URL",
        Entries: entries.map(([messageId, message]) => {
           ...
        }),
      });
      const commandOutput = await sqsClient.send(command);

I get the type error:

image
Argument of type 'SendMessageBatchCommand' is not assignable to parameter of type 'Command<ServiceInputTypes, SendMessageBatchCommandInput, ServiceOutputTypes, SendMessageBatchCommandOutput, SmithyResolvedConfiguration<...>>'.
  Types of property 'resolveMiddleware' are incompatible.
    Type '(clientStack: MiddlewareStack<ServiceInputTypes, ServiceOutputTypes>, configuration: SQSClientResolvedConfig, options?: HttpHandlerOptions | undefined) => Handler<...>' is not assignable to type '(stack: MiddlewareStack<ServiceInputTypes, ServiceOutputTypes>, configuration: SmithyResolvedConfiguration<HttpHandlerOptions>, options: any) => Handler<...>'.
      Types of parameters 'clientStack' and 'stack' are incompatible.
        Type 'import("/Users/richard.garner/git/my-project/node_modules/@smithy/signature-v4/node_modules/@smithy/types/dist-types/middleware").MiddlewareStack<import("/Users/richard.garner/git/my-project/node_modules/@aws-sdk/client-sqs/dist-types/SQSClient").ServiceInputTypes, import("/Users/ri...' is not assignable to type 'import("/Users/richard.garner/git/my-project/node_modules/@smithy/types/dist-types/middleware").MiddlewareStack<import("/Users/richard.garner/git/my-project/node_modules/@aws-sdk/client-sqs/dist-types/SQSClient").ServiceInputTypes, import("/Users/richard.garner/git/hazardwatch/packa...'.
          Types of property 'concat' are incompatible.
            Type '<InputType extends import("/Users/richard.garner/git/my-project/node_modules/@aws-sdk/client-sqs/dist-types/SQSClient").ServiceInputTypes, OutputType extends import("/Users/richard.garner/git/my-project/node_modules/@aws-sdk/client-sqs/dist-types/SQSClient").ServiceOutputTypes>(from...' is not assignable to type '<InputType extends import("/Users/richard.garner/git/my-project/node_modules/@aws-sdk/client-sqs/dist-types/SQSClient").ServiceInputTypes, OutputType extends import("/Users/richard.garner/git/my-project/node_modules/@aws-sdk/client-sqs/dist-types/SQSClient").ServiceOutputTypes>(from...'. Two different types with this name exist, but they are unrelated.
              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 'ServiceOutputTypes'.
                                          Type 'SendMessageBatchCommandOutput' is not assignable to type 'OutputType'.
                                            'SendMessageBatchCommandOutput' is assignable to the constraint of type 'OutputType', but 'OutputType' could be instantiated with a different subtype of constraint 'ServiceOutputTypes'.ts(2345)
richgarner-nsw-gov commented 1 year ago

On further investigation it seems to be resolved by rolling back @aws-sdk/client-sqs from 3.363.0 to 3.362.0.

kuhe commented 1 year ago

check your lockfile for multiple installed versions of @smithy/types. Upgrade the dependency such that your lockfile only contains one version of it, and that should fix the compilation error.