From 7c19ff679ae2e05a756cd1186abc0755e05eece3 Mon Sep 17 00:00:00 2001 From: Benjamin Hutchins Date: Thu, 14 Sep 2023 14:16:55 -0400 Subject: [PATCH] feat: allow arrays to be passed via set Since set attributes accept Sets or Arrays, want to expose this directly only the .set method to make it easier for some use cases. --- src/decorator/attribute-types/string-set.spec.ts | 2 +- src/table.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/decorator/attribute-types/string-set.spec.ts b/src/decorator/attribute-types/string-set.spec.ts index e649268..dc1a3e5 100644 --- a/src/decorator/attribute-types/string-set.spec.ts +++ b/src/decorator/attribute-types/string-set.spec.ts @@ -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']) }) }) diff --git a/src/table.ts b/src/table.ts index ffd7360..bc1f7ff 100644 --- a/src/table.ts +++ b/src/table.ts @@ -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

>(propertyName: P | string, value: this[P], params?: SetPropParams): this { + public set

>(propertyName: P | string, value: this[P] extends Set ? Set | E[] : this[P], params?: SetPropParams): this { const attribute = this.table.schema.getAttributeByPropertyName(propertyName as string) return this.setByAttribute(attribute, value, params) }