Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overloading confusion on marshall #6253

Closed
3 tasks done
alex-at-cascade opened this issue Jul 3, 2024 · 7 comments
Closed
3 tasks done

Overloading confusion on marshall #6253

alex-at-cascade opened this issue Jul 3, 2024 · 7 comments
Assignees
Labels
bug This issue is a bug. closed-for-staleness p2 This is a standard priority issue pending-release This issue will be fixed by an approved PR that hasn't been released yet.

Comments

@alex-at-cascade
Copy link

alex-at-cascade commented Jul 3, 2024

Checkboxes for prior research

Describe the bug

Starting with 3.598.0 when calling marshall on a variable typed as a simple object, the following error is reported:

marshallTest.ts:12:3 - error TS2322: Type 'BMember' is not assignable to type 'Record<string, AttributeValue>'.
  Index signature for type 'string' is missing in type 'BMember'.

NOTE: the problem only occurs when using a typed variable. Having a literal object as the param directly still works fine. Also, the problem does NOT occur in 3.596.0 or before.

SDK version number

@aws-sdk/package-name@version, ...

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

v18.18.2
"typescript": "^5.5.3"

Reproduction Steps

Try to compile this file, marshallTest.ts:

import { DynamoDB } from "@aws-sdk/client-dynamodb";
import { marshall } from "@aws-sdk/util-dynamodb";

const dynamoDB = new DynamoDB({});

const myItem = {
  foo: "bar",
};

const p = dynamoDB.putItem({
  TableName: "mytable",
  Item: marshall(myItem),
});

Observed Behavior

above error occurred

Expected Behavior

no error should occur

Possible Solution

probably something to do with the order of type declarations (it appears reordering has already been attempted several times)

Additional Information/Context

No response

@alex-at-cascade alex-at-cascade added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 3, 2024
@RanVaknin RanVaknin self-assigned this Jul 3, 2024
@kuhe
Copy link
Contributor

kuhe commented Jul 3, 2024

Could you make a reproduction repository of this? I don't get a compiler error with the example.

@kuhe kuhe self-assigned this Jul 3, 2024
@kuhe kuhe added response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. p2 This is a standard priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Jul 3, 2024
@kuhe
Copy link
Contributor

kuhe commented Jul 3, 2024

marshall(myItem) in the example resolves to the signature

export declare function marshall(data: Map<string, NativeAttributeValue> | Record<string, NativeAttributeValue>, options?: marshallOptions): Record<string, AttributeValue>;

which matches the type of Item

@alex-at-cascade
Copy link
Author

Your result is definitely what I was expecting. I wonder if my tsconfig.json would impact it?

{
  "compilerOptions": {
    "lib": ["es2020"],
    "module": "commonjs",
    "target": "es2020",
    "outDir": "build",
    "sourceMap": true,
    "importHelpers": true,
    "strict": true,
    "esModuleInterop": true,
    "allowJs": true,
    "resolveJsonModule": true
  },
  "exclude": ["node_modules"],
  "include": ["*.ts"]
}

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. label Jul 4, 2024
@kuhe
Copy link
Contributor

kuhe commented Jul 8, 2024

My test works with that tsconfig too, so you'll have to provide a reproduction sample repository.

@kuhe kuhe added the response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. label Jul 8, 2024
@RanVaknin RanVaknin removed their assignment Jul 8, 2024
@ininrobu
Copy link

ininrobu commented Jul 9, 2024

I'm seeing this issue as well, though I don't have a concise reproduction handy. I believe the cause is this change: https://github.com/aws/aws-sdk-js-v3/pull/6195/files#diff-5cb8b8aa06642c3dd60ce3fd1ebdcd54c5258b790d3956fb1b6ade503b00654cL42
Specifically the fact that it reordered the marshal overloads and now has the NativeAttributeBinary variant before the others that would match complex objects. That type is a union including File which is basically anything, causing the incorrect signature match. They key here is the comment where File is declared - if your tsconfig does not include the DOM definitions then you'll hit this issue because File is such a wide-matching type. Adding DOM to the tsconfig lib works around the issue, but imo it's really an SDK bug.

@kuhe kuhe added the pending-release This issue will be fixed by an approved PR that hasn't been released yet. label Jul 9, 2024
@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. label Jul 10, 2024
@kuhe
Copy link
Contributor

kuhe commented Jul 10, 2024

Should be fixed in today's release by PR #6261. The expected version is https://github.com/aws/aws-sdk-js-v3/releases/tag/v3.614.0.

@kuhe kuhe added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Jul 10, 2024
@github-actions github-actions bot added closed-for-staleness and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Jul 15, 2024
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug. closed-for-staleness p2 This is a standard priority issue pending-release This issue will be fixed by an approved PR that hasn't been released yet.
Projects
None yet
Development

No branches or pull requests

4 participants