aws / aws-sdk-js-v3

Modularized AWS SDK for JavaScript.
Apache License 2.0
2.95k stars 554 forks source link

Enum instead of string #6215

Open autarchprinceps opened 4 days ago

autarchprinceps commented 4 days ago

Describe the issue

The documentation claims that you can provide InstanceTypes as an array of strings, when in fact that will result in a hard error, since at some point it has been changed to some kind of enum type, the use of which I cannot find any documentation for.

> let type: string = 't4g.micro';
> new DescribeInstanceTypesCommand({InstanceTypes: [type]})
<repl>.ts:6:5 - error TS2769: No overload matches this call.
  Overload 1 of 2, '(input: DescribeInstanceTypesCommandInput): DescribeInstanceTypesCommand', gave the following error.
    Type 'string' is not assignable to type '_InstanceType'.
  Argument of type '[{ InstanceTypes: string[]; }]' is not assignable to parameter of type '[] | [DescribeInstanceTypesCommandInput]'.
    Type '[{ InstanceTypes: string[]; }]' is not assignable to type '[DescribeInstanceTypesCommandInput]'.
      Type '{ InstanceTypes: string[]; }' is not assignable to type 'DescribeInstanceTypesCommandInput'.
        Types of property 'InstanceTypes' are incompatible.
          Type 'string[]' is not assignable to type '_InstanceType[]'.
            Type 'string' is not assignable to type '_InstanceType'.

6 new DescribeInstanceTypesCommand({InstanceTypes: [type]})
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

By the way, next time you do such changes, how about you make them compatible to the old behaviour instead, given this was a breaking change right in the middle of ordinary releases.

Links

https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/ec2/command/DescribeInstanceTypesCommand/

aBurmeseDev commented 3 days ago

Hi @autarchprinceps - thanks for reaching out and sorry to hear about the issue.

Can you please share your SDK code to help us understand the issue better? Also what version were you using before updating so that I can check if there was any major changes?

Here's code example I used to reproduce but was unable to.

import { EC2Client, DescribeInstanceTypesCommand } from "@aws-sdk/client-ec2";
const client = new EC2Client({ region: "us-west-1" });
const input = {
  DryRun: true,
  InstanceTypes: ["a1.medium" || "c3.xlarge"],
};
const command = new DescribeInstanceTypesCommand(input);
const response = await client.send(command);
autarchprinceps commented 19 hours ago

I thought I did. I guess I didn't include the import, but otherwise it's really just the two lines I mentioned.

import { DescribeInstanceTypesCommand } from "@aws-sdk/client-ec2";
let type: string = 't4g.micro';
new DescribeInstanceTypesCommand({InstanceTypes: [type]})

is the smallest complete code to reproduce the issue. This breaks in ts-node repl interactively, but also in tsc when compiling it. Of course for us it is originally embedded in a much longer program, but the issue remains the same, and this in ts-node serves as an easy example of making it break. If you give over a string type variable, it responds with: Type 'string' is not assignable to type '_InstanceType'. If this only works with string literals now, and not variables, that really impairs automation. In our case we are getting the instance type out of another API that returns string, RDS in the case, to then find out the memory size via this API to calculate the max connections. But other examples have similar issues with your new enum style types. _InstanceType is mainly the first example.