aws / aws-sdk-js

AWS SDK for JavaScript in the browser and Node.js
https://aws.amazon.com/developer/language/javascript/
Apache License 2.0
7.59k stars 1.55k forks source link

In Typescript, SQS.CreateQueueCommand requires all queue attributes due to `Attributes` having type `Record<QueueAttributeName, string>` #4510

Closed suchanpark-koioi closed 11 months ago

suchanpark-koioi commented 11 months ago

Describe the bug

A simple code below:

const sqsClient = new SQSClient();
const createCommandOutput = await sqsClient.send(
  new CreateQueueCommand({
    QueueName: queueName,
    Attributes: {
      RedrivePolicy: JSON.stringify({
        maxReceiveCount: '5',
      }),
    },
  }),
);

gives TypeScript error as follows:

TS2740: Type  { RedrivePolicy: string; }  is missing the following properties from type  Record<QueueAttributeName, string> :
All, ApproximateNumberOfMessages, ApproximateNumberOfMessagesDelayed, ApproximateNumberOfMessagesNotVisible
, and  17  more.

Expected Behavior

This code should compile with Typescript.

Specifiying all the parameters is not required, it can be seen as, for example, here: https://docs.aws.amazon.com/cli/latest/reference/sqs/create-queue.html

This code didn't produce Typescript Error at least until 3.421.0.

Current Behavior

Typescript error that says as below:

TS2740: Type  { RedrivePolicy: string; }  is missing the following properties from type  Record<QueueAttributeName, string> :
All, ApproximateNumberOfMessages, ApproximateNumberOfMessagesDelayed, ApproximateNumberOfMessagesNotVisible
, and  17  more.

Reproduction Steps

import {
  CreateQueueCommand,
  SQSClient,
} from '@aws-sdk/client-sqs';

const sqsClient = new SQSClient();
const createCommandOutput = await sqsClient.send(
  new CreateQueueCommand({
    QueueName: 'anyname',
    Attributes: {
      RedrivePolicy: JSON.stringify({
        maxReceiveCount: '5',
      }),
    },
  }),
);

Use aws-sdk with version >=3.430.0 for example, and run tsc

Possible Solution

Change the type of Attributes into something like Partial< Record<QueueAttributeName, string> >?

Additional Information/Context

No response

SDK version used

3.431.0

Environment details (OS name and version, etc.)

Typescript 5.2.2, Node 18.15.0, MacOS 14.0 (23A344)

suchanpark-koioi commented 11 months ago

Wrong repository, sorry