dynamodb-toolbox
dynamodb-toolbox copied to clipboard
Cannot use 'set' type Entity attribute with explicit model type
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.
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.