Skip to content

Commit

Permalink
feat: allow arrays to be passed via set
Browse files Browse the repository at this point in the history
Since set attributes accept Sets or Arrays, want to expose this directly
only the .set method to make it easier for some use cases.
  • Loading branch information
benhutchins committed Sep 14, 2023
1 parent 8d724cd commit 7c19ff6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/decorator/attribute-types/string-set.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('AttributeType/StringSet', () => {

it('should allow values to be an Array', () => {
expect(record.testStringSet).eq(null)
record.testStringSet = ['some value'] as any
record.set('testStringSet', ['some value'])
expect(Array.from(record.testStringSet)).deep.eq(['some value'])
})
})
Expand Down
2 changes: 1 addition & 1 deletion src/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ export class Table {
* @see {@link Table.setAttribute} To set an attribute value by an attribute name.
* @see {@link Table.setAttributes} To set several attribute values by attribute names.
*/
public set<P extends TableProperty<this>>(propertyName: P | string, value: this[P], params?: SetPropParams): this {
public set<P extends TableProperty<this>>(propertyName: P | string, value: this[P] extends Set<infer E> ? Set<E> | E[] : this[P], params?: SetPropParams): this {
const attribute = this.table.schema.getAttributeByPropertyName(propertyName as string)
return this.setByAttribute(attribute, value, params)
}
Expand Down

0 comments on commit 7c19ff6

Please sign in to comment.