Skip to content

Commit 851c6a7

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

File tree

6 files changed

+35
-8
lines changed

6 files changed

+35
-8
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ export interface ClientSession extends Record<string, unknown> {
143143
}
144144

145145
// @public
146-
export interface CommonEventProperties<T = Record<string, unknown>> {
146+
export interface CommonEventProperties<T extends {
147+
[_: string]: unknown;
148+
} = Record<string, unknown>> {
147149
context?: Array<SelfDescribingJson<T>> | null;
148150
// Warning: (ae-forgotten-export) The symbol "Timestamp" needs to be exported by the entry point index.module.d.ts
149151
timestamp?: Timestamp | null;
@@ -323,7 +325,9 @@ export interface SelfDescribingEvent {
323325
}
324326

325327
// @public
326-
export type SelfDescribingJson<T extends Record<keyof T, unknown> = Record<string, unknown>> = {
328+
export type SelfDescribingJson<T extends {
329+
[_: string]: unknown;
330+
} = Record<string, unknown>> = {
327331
schema: string;
328332
data: T;
329333
};

api-docs/docs/node-tracker/node-tracker.api.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,9 @@ export interface SelfDescribingEvent {
305305
}
306306

307307
// @public
308-
export type SelfDescribingJson<T extends Record<keyof T, unknown> = Record<string, unknown>> = {
308+
export type SelfDescribingJson<T extends {
309+
[_: string]: unknown;
310+
} = Record<string, unknown>> = {
309311
schema: string;
310312
data: T;
311313
};
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)