@@ -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 { [ _ : string ] : unknown } = Record < string , unknown > > = {
48+ export type SelfDescribingJson < T = Record < string , unknown > > = {
4949 /**
5050 * The schema string
5151 * @example 'iglu:com.snowplowanalytics.snowplow/web_page/jsonschema/1-0-0'
@@ -54,14 +54,14 @@ export type SelfDescribingJson<T extends { [_: string]: unknown } = Record<strin
5454 /**
5555 * The data object which should conform to the supplied schema
5656 */
57- data : T ;
57+ data : T extends any [ ] ? never : T extends { } ? T : never ;
5858} ;
5959
6060/**
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 { [ _ : string ] : unknown } = Record < string , unknown > > = {
64+ export type SelfDescribingJsonArray < T = Record < string , unknown > > = {
6565 /**
6666 * The schema string
6767 * @example 'iglu:com.snowplowanalytics.snowplow/contexts/jsonschema/1-0-1'
@@ -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 extends { [ _ : string ] : unknown } = Record < string , unknown > > {
122+ export interface CommonEventProperties < T = 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 */
@@ -382,9 +382,9 @@ export function trackerCore(configuration: CoreConfiguration = {}): TrackerCore
382382 * @param timestamp - Timestamp of the event
383383 * @returns Payload after the callback is applied or undefined if the event is skipped
384384 */
385- function track (
385+ function track < C = Record < string , unknown > > (
386386 pb : PayloadBuilder ,
387- context ?: Array < SelfDescribingJson > | null ,
387+ context ?: Array < SelfDescribingJson < C > > | null ,
388388 timestamp ?: Timestamp | null
389389 ) : Payload | undefined {
390390 pb . withJsonProcessor ( payloadJsonProcessor ( encodeBase64 ) ) ;
@@ -565,9 +565,9 @@ export function trackerCore(configuration: CoreConfiguration = {}): TrackerCore
565565 * A custom event type, allowing for an event to be tracked using your own custom schema
566566 * and a data object which conforms to the supplied schema
567567 */
568- export interface SelfDescribingEvent {
568+ export interface SelfDescribingEvent < T = Record < string , unknown > > {
569569 /** The Self Describing JSON which describes the event */
570- event : SelfDescribingJson ;
570+ event : SelfDescribingJson < T > ;
571571}
572572
573573/**
@@ -578,7 +578,7 @@ export interface SelfDescribingEvent {
578578 * @param event - Contains the properties and schema location for the event
579579 * @returns PayloadBuilder to be sent to {@link @snowplow/tracker-core#TrackerCore.track }
580580 */
581- export function buildSelfDescribingEvent ( event : SelfDescribingEvent ) : PayloadBuilder {
581+ export function buildSelfDescribingEvent < T = Record < string , unknown > > ( event : SelfDescribingEvent < T > ) : PayloadBuilder {
582582 const {
583583 event : { schema, data } ,
584584 } = event ,
0 commit comments