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

Type inference for conditional update #487

Open
ajanim opened this issue Mar 31, 2023 · 6 comments · May be fixed by #488
Open

Type inference for conditional update #487

ajanim opened this issue Mar 31, 2023 · 6 comments · May be fixed by #488
Assignees
Labels
bug Something isn't working

Comments

@ajanim
Copy link

ajanim commented Mar 31, 2023

Looking to run a conditional update based on the existence of a particular attribute. I expect the type of updatedProgress to match the full entity, but the inferred type is an object which only includes SK. The object returned does include all properties (contrary to the type inference).

This version has the correct expected return type.

const { Attributes: updatedProgress } = await ProgressEntity.update(
        {
          PK1,
          PK2,
          SK,
          date,
        },
        {
          conditions: [],
          returnValues: 'ALL_NEW',
        },
      );

This version does not.

const { Attributes: updatedProgress } = await ProgressEntity.update(
        {
          PK1,
          PK2,
          SK,
          date,
        },
        {
          conditions: [
            {
              attr: 'SK',
              exists: true,
            },
          ],
          returnValues: 'ALL_NEW',
        },
      );
@aldebout
Copy link

Might be related to #367 @naorpeled

@naorpeled
Copy link
Collaborator

Hey @ajanim and @aldebout,
will take a look after finishing #471,
I hope that's okay 🙏

@naorpeled
Copy link
Collaborator

I think I found out what the issue is,
started working on a PR that should fix it.
Will continue tomorrow, will keep you guys updated!

@mattes3
Copy link

mattes3 commented Jan 14, 2024

Hi, even in V0.9.2 I still don't get the Attributes type correctly when my update call looks like this:

const result = await UserEntity.update(
                    {
                        id,
                        name,
                        email,
                    },
                    { conditions: { attr: 'pk', exists: false }, returnValues: 'ALL_NEW' },
                );

Is there any news on this?

@dvictory
Copy link
Contributor

Looks like @naorpeled started a draft but didn't finish

@naorpeled
Copy link
Collaborator

naorpeled commented Mar 3, 2024

Hey guys,
will give this a look ASAP.

Sorry for disappearing, had a lot of things to deal with IRL 😢

@naorpeled naorpeled added the bug Something isn't working label Mar 3, 2024
@naorpeled naorpeled self-assigned this Mar 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants