Skip to content

Commit 1c3417f

Browse files
committed
Fix SelfDescribingJson type to allow optional keys in type parameter
1 parent d97797f commit 1c3417f

File tree

5 files changed

+28
-7
lines changed

5 files changed

+28
-7
lines changed

api-docs/docs/browser-tracker/browser-tracker.api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export interface ActivityTrackingConfigurationCallback {
2929
}
3030

3131
// @public
32-
export function addGlobalContexts(contexts: Array<ConditionalContextProvider | ContextPrimitive>, trackers?: Array<string>): void;
32+
export function addGlobalContexts(contexts: Array<ConditionalContextProvider | ContextPrimitive> | Record<string, ConditionalContextProvider | ContextPrimitive>, trackers?: Array<string>): void;
3333

3434
// @public
3535
export function addPlugin(configuration: BrowserPluginConfiguration, trackers?: Array<string>): void;
@@ -293,7 +293,7 @@ export function preservePageViewId(trackers?: Array<string>): void;
293293
export type PreservePageViewIdForUrl = boolean | "full" | "pathname" | "pathnameAndSearch";
294294

295295
// @public
296-
export function removeGlobalContexts(contexts: Array<ConditionalContextProvider | ContextPrimitive>, trackers?: Array<string>): void;
296+
export function removeGlobalContexts(contexts: Array<ConditionalContextProvider | ContextPrimitive | string>, trackers?: Array<string>): void;
297297

298298
// @public
299299
export type RequestFailure = {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@snowplow/browser-plugin-snowplow-ecommerce",
5+
"comment": "",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@snowplow/browser-plugin-snowplow-ecommerce"
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@snowplow/tracker-core",
5+
"comment": "Fix SelfDescribingJson type to allow optional keys in type parameter",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@snowplow/tracker-core"
10+
}

libraries/tracker-core/src/core.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import { LOG } from './logger';
4545
* Export interface for any Self-Describing JSON such as context or Self Describing events
4646
* @typeParam T - The type of the data object within a SelfDescribingJson
4747
*/
48-
export type SelfDescribingJson<T extends Record<keyof T, unknown> = Record<string, unknown>> = {
48+
export type SelfDescribingJson<T extends { [_: string]: unknown } = Record<string, unknown>> = {
4949
/**
5050
* The schema string
5151
* @example 'iglu:com.snowplowanalytics.snowplow/web_page/jsonschema/1-0-0'
@@ -61,7 +61,7 @@ export type SelfDescribingJson<T extends Record<keyof T, unknown> = Record<strin
6161
* Export interface for any Self-Describing JSON which has the data attribute as an array
6262
* @typeParam T - The type of the data object within the SelfDescribingJson data array
6363
*/
64-
export type SelfDescribingJsonArray<T extends Record<keyof T, unknown> = Record<string, unknown>> = {
64+
export type SelfDescribingJsonArray<T extends { [_: string]: unknown } = Record<string, unknown>> = {
6565
/**
6666
* The schema string
6767
* @example 'iglu:com.snowplowanalytics.snowplow/contexts/jsonschema/1-0-1'
@@ -70,7 +70,7 @@ export type SelfDescribingJsonArray<T extends Record<keyof T, unknown> = Record<
7070
/**
7171
* The data array which should conform to the supplied schema
7272
*/
73-
data: Array<T>;
73+
data: (T extends SelfDescribingJson ? T : SelfDescribingJson<T>)[];
7474
};
7575

7676
/**
@@ -119,7 +119,7 @@ function getTimestamp(timestamp?: Timestamp | null): TimestampPayload {
119119
}
120120

121121
/** Additional data points to set when tracking an event */
122-
export interface CommonEventProperties<T = Record<string, unknown>> {
122+
export interface CommonEventProperties<T extends { [_: string]: unknown } = Record<string, unknown>> {
123123
/** Add context to an event by setting an Array of Self Describing JSON */
124124
context?: Array<SelfDescribingJson<T>> | null;
125125
/** Set the true timestamp or overwrite the device sent timestamp on an event */

plugins/browser-plugin-snowplow-ecommerce/src/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,8 @@ export interface User {
317317
email?: string;
318318
}
319319

320-
export interface CommonEcommerceEventProperties<T = Record<string, unknown>> extends CommonEventProperties<T> {
320+
export interface CommonEcommerceEventProperties<T extends { [_: string]: unknown } = Record<string, unknown>>
321+
extends CommonEventProperties<T> {
321322
/** Add context to an event by setting an Array of Self Describing JSON */
322323
context?: Array<SelfDescribingJson<T>>;
323324
}

0 commit comments

Comments
 (0)