aws / aws-sdk-js-v3

Modularized AWS SDK for JavaScript.
Apache License 2.0
3.12k stars 578 forks source link

Type assignment errors #6420

Open menkari opened 2 months ago

menkari commented 2 months ago

Checkboxes for prior research

Describe the bug

Brand new application, I'm receiving argument type errors when instantiating the S3Client and assigning any operation to the .send() function.

new S3Client error:

Argument type {region: string} is not assignable to parameter type __CheckOptionalClientConfig<S3ClientConfig>

.send() command error:

Argument type ListBucketsCommand is not assignable to parameter type Command<ServiceInputTypes, SI, ServiceOutputTypes, SO, SmithyResolvedConfiguration<__HttpHandlerOptions>>

SDK version number

@aws-sdk/client-s3@3.637.0

Which JavaScript Runtime is this issue in?

Browser

Details of the browser/Node.js/ReactNative version

v20.16.0

Reproduction Steps

This looks to be a continuation of #4928

Minimally reproducible application using Angular 18 via ng-cli, vanilla setup, SCSS.

home.component.ts

import { Component } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import {S3Client} from "@aws-sdk/client-s3";

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [RouterOutlet],
  templateUrl: './app.component.html',
  styleUrl: './app.component.scss'
})
export class AppComponent {
  title = 'awsTester';

  s3Client: S3Client;

  constructor() {

    console.log("Testing S3...");

    this.s3Client = new S3Client({
      region: 'ap-southeast-2'
    });

  }

}

package.json

{
  "name": "aws-tester",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^18.1.0",
    "@angular/common": "^18.1.0",
    "@angular/compiler": "^18.1.0",
    "@angular/core": "^18.1.0",
    "@angular/forms": "^18.1.0",
    "@angular/platform-browser": "^18.1.0",
    "@angular/platform-browser-dynamic": "^18.1.0",
    "@angular/router": "^18.1.0",
    "@aws-sdk/client-s3": "^3.637.0",
    "rxjs": "~7.8.0",
    "tslib": "^2.3.0",
    "zone.js": "~0.14.3"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^18.1.3",
    "@angular/cli": "^18.1.3",
    "@angular/compiler-cli": "^18.1.0",
    "@types/jasmine": "~5.1.0",
    "jasmine-core": "~5.1.0",
    "karma": "~6.4.0",
    "karma-chrome-launcher": "~3.2.0",
    "karma-coverage": "~2.2.0",
    "karma-jasmine": "~5.1.0",
    "karma-jasmine-html-reporter": "~2.1.0",
    "typescript": "~5.5.2"
  }
}

Observed Behavior

Unable to compile the application due to argument type errors

Expected Behavior

The application should function according to API documentation with the prescribed types.

Possible Solution

Unknown. Have seen this issue previously. Fixes weren't conveyed. Have attempted package.json lock file and node-modules folder delete. Have started from scratch with no success either.

Additional Information/Context

Currently using webstorm, macos

menkari commented 2 months ago

yeah @africanobyamugisha I'm pretty sure sending someone a random zip file ain't the solution bro 🤪

zshzbh commented 2 months ago

Hey @menkari ,

Thanks for the feedback! However I can't reproduce this issue. Code I have :


import { S3Client, ListObjectsCommand } from "@aws-sdk/client-s3";

// Create an S3 client
var config = {
  region: "us-east-1",
  credentials: {
    accessKeyId: "***",
    secretAccessKey: "***",
  },
};

const client = new S3Client(config);
var bucketParams = { Bucket: "new-bucket-maggie-ma" };

var listObjectsCommand = new ListObjectsCommand(bucketParams);
client
  .send(listObjectsCommand)
  .then(function (data) {
    console.log("Success", data);
  })
  .catch(function (err) {
    console.error(err);
  });

In order to find the root cause, could you please send over the parameters that you put on the ListBucketsCommand?

Thanks! Maggie

menkari commented 2 months ago

@zshzbh Its every command, not just ListBucketsCommand - As I understand, the command doesn't require any parameters anyway. But even with the most basic of GetObjectCommand

const response = this.s3Client.send(new GetObjectCommand({
      Bucket: 'my-bucket',
      Key: 'my-key'}
    }));

Also returns the type error of

Argument type GetObjectCommand is not assignable to parameter type Command<ServiceInputTypes, SI, ServiceOutputTypes, SO, SmithyResolvedConfiguration<__HttpHandlerOptions>>

I've pushed the minimal application here for cloning: https://github.com/neon-light-dev/awsTester

zshzbh commented 1 month ago

Hey @menkari, I put ListObjectsCommand in my repro code and it does require parameters -

  import { S3Client, ListObjectsCommand } from "@aws-sdk/client-s3"; // ES Modules import
  // const { S3Client, ListObjectsCommand } = require("@aws-sdk/client-s3"); // CommonJS import
  const client = new S3Client(config);
  const input = { // ListObjectsRequest
    Bucket: "STRING_VALUE", // required
    Delimiter: "STRING_VALUE",
    EncodingType: "url",
    Marker: "STRING_VALUE",
    MaxKeys: Number("int"),
    Prefix: "STRING_VALUE",
    RequestPayer: "requester",
    ExpectedBucketOwner: "STRING_VALUE",
    OptionalObjectAttributes: [ // OptionalObjectAttributesList
      "RestoreStatus",
    ],
  };

Could you please delete the lock file and node modules and reinstall the latest sdk version ?