dynamodb-toolbox icon indicating copy to clipboard operation
dynamodb-toolbox copied to clipboard

Cannot use 'set' type Entity attribute with explicit model type

Open craPkit opened this issue 3 years ago • 1 comments

Using a generic specifier on an Entity with an attribute of e.g. { type: 'set', setType: 'string' } causes the following TS error on update:

Type '{ $delete: string[]; }' is not assignable to type 'string[]'.

The same issue occurs with typing a number and using $add to increase it during an update.

Example:

const Customer = new Entity<{
  id: string;
  sk: string;
  count: number;
  stringSet: string[];
}>({
  name: 'Customer',
  attributes: {
    id: { partitionKey: true }, // flag as partitionKey
    sk: { sortKey: true }, // flag as sortKey
    count: { type: 'number' },
    stringSet: { type: 'set', setType: 'string' }
  },
  table: MyTable
});

Customer.update({
  id: 'foo',
  sk: 'bar',
  count: { $add: 1 }, // TS error similar to the above 
  stringSet: { $add: ['baz'] } // above TS error
});

It works without the generic specifier on Entity.

craPkit avatar Mar 08 '21 08:03 craPkit

Hey @craPkit, wanted to let you know that I started working on this and hopefully will manage to finish this by the end of this week.

naorpeled avatar Sep 12 '22 12:09 naorpeled