From a6ddf9f369fb0240f7fe9ca7040ef36a48a65d41 Mon Sep 17 00:00:00 2001 From: Xinyi Ye Date: Tue, 5 Nov 2024 15:32:44 -0800 Subject: [PATCH] fix(analytics-types): allow an array of objects as identity value type (#914) --- packages/analytics-core/test/identify.test.ts | 22 +++++++++++++++++++ packages/analytics-types/src/event.ts | 3 ++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/analytics-core/test/identify.test.ts b/packages/analytics-core/test/identify.test.ts index 324d145f9..ca264cf87 100644 --- a/packages/analytics-core/test/identify.test.ts +++ b/packages/analytics-core/test/identify.test.ts @@ -186,4 +186,26 @@ describe('Identify class', () => { expect(identify.getUserProperties()).toStrictEqual(expectedProperties); }); + + test('should allow to set an array of objects', () => { + const identify = new Identify(); + const propertyValue = [ + { + key1: 'value1', + key2: 'value2', + }, + { + key1: 'value3', + key2: 'value4', + }, + ]; + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore bypassing ts rules to test unexpected input + identify.set('PROPERTY_NAME', propertyValue); + const expectedProperties = { + [IdentifyOperation.SET]: { PROPERTY_NAME: propertyValue }, + }; + + expect(identify.getUserProperties()).toStrictEqual(expectedProperties); + }); }); diff --git a/packages/analytics-types/src/event.ts b/packages/analytics-types/src/event.ts index 83ee9bbf9..da5cd635c 100644 --- a/packages/analytics-types/src/event.ts +++ b/packages/analytics-types/src/event.ts @@ -39,7 +39,8 @@ export type ValidPropertyType = | string | boolean | Array - | { [key: string]: ValidPropertyType }; + | { [key: string]: ValidPropertyType } + | Array<{ [key: string]: ValidPropertyType }>; interface BaseOperationConfig { [key: string]: ValidPropertyType;