skip to Main Content

I’m pretty new to Typescript, so maybe I’m overlooking something obvious, but I’m unable to use the AWS v3 Javascript SDK without triggering what appear to be totally bogus @typescript-eslint warnings. Here’s a trivial snippet that reproduces one inconsistency:

import { S3Client } from "@aws-sdk/client-s3";
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
new S3Client({});
new DynamoDBClient({});

The S3 client construction is fine. No warnings.
However, the last line with the DynamoDB client construction yields ESLint: Unsafe construction of an any type value.(@typescript-eslint/no-unsafe-call)

This is basically straight out of their "hello dynamodb" docs.

Both packages are installed, and the types look basically the same, though there could be some subtlety buried in the details of the configuration types, I guess (slightly simplified for clarity):

export declare class S3Client extends __Client<__HttpHandlerOptions, ServiceInputTypes, ServiceOutputTypes, S3ClientResolvedConfig> {
    readonly config: S3ClientResolvedConfig;
    constructor(configuration: S3ClientConfig);
}

vs

export declare class DynamoDBClient extends __Client<__HttpHandlerOptions, ServiceInputTypes, ServiceOutputTypes, DynamoDBClientResolvedConfig> {
    readonly config: DynamoDBClientResolvedConfig;
    constructor(configuration: DynamoDBClientConfig);
}

They look basically the same. How can a constructor be considered to return an any? That’s so weird.

My package.json contains:

  "dependencies": {
    "@aws-sdk/client-dynamodb": "^3.351.0",
    "@aws-sdk/client-s3": "^3.282.0",
...

2

Answers


  1. Chosen as BEST ANSWER

    This seems to be a build/tooling caching problem. If I run eslint from the command line, I don't get any errors, but inside WebStorm 2022.3.2, the eslint warning persists on the every new DynamoDBClient() even if I completely clear the line and retype it, add a second copy, change the parameters, paste the code into a new file in the same project, etc.

    I was able to clear the spurious warning by doing a File > Invalidate Caches... > Just Restart. Perhaps a regular restart would have also been enough.

    The repro (for WebStorm) seems to be to reference the class with eslint tooling enabled before doing a npm install of the associated package. The error is then sticky even after installing the package. Not sure if this is a general problem with eslint-before-definition (I'd assume lots of people would hit that!) or if there's something about the complexity of the AWS code that triggers the issue.

    Leaving this question up just in case anyone else using WebStorm bumps into the same issue!


  2. I don’t see this issue using the following latest versions of both packages:

    {
      "dependencies": {
        "@aws-sdk/client-dynamodb": "^3.352.0",
        "@aws-sdk/client-s3": "^3.352.0",
        "@aws-sdk/lib-dynamodb": "^3.272.0"
      },
      "type": "module"
    }
    

    Are you able to provide reproducible code which I can investigate?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search