Skip to content

Commit ab8cea3

Browse files
authored
use object rather than JSON type (#578)
* use object rather than JSON type Co-authored-by: Seth Silesky <silesky@users.noreply.github.com>
1 parent 6880668 commit ab8cea3

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

.changeset/pink-carrots-serve.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@segment/analytics-next': patch
3+
---
4+
5+
Loosen SegmentEvent and Traits typescript interface back to 'object' (Fixes [#575](https://github.com/segmentio/analytics-next/issues/575))

packages/browser/src/core/events/interfaces.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,6 @@ export type JSONValue = JSONPrimitive | JSONObject | JSONArray
77
export type JSONObject = { [member: string]: JSONValue }
88
export type JSONArray = JSONValue[]
99

10-
/**
11-
* A JSON object that allows undefined key/values which will be completely removed during serialization.
12-
*/
13-
export type JSONObjectLoose = {
14-
[member: string]: JSONValueLoose | undefined
15-
}
16-
17-
export type JSONValueLoose = JSONPrimitive | JSONObjectLoose | JSONValueLoose[]
18-
1910
export type Callback = (ctx: Context) => Promise<unknown> | unknown
2011

2112
export type Integrations = {
@@ -109,8 +100,26 @@ interface AnalyticsContext {
109100
[key: string]: any
110101
}
111102

112-
export type Traits = JSONObjectLoose
113-
export type EventProperties = JSONObjectLoose
103+
// "object" is not ideal, but with JSONObject, we ran into at least one bad edge case around index sig.
104+
105+
/**
106+
* An object literal representing traits
107+
* - identify: https://segment.com/docs/connections/spec/identify/#traits
108+
* - group: https://segment.com/docs/connections/spec/group/#traits
109+
* @example
110+
* { name: "john", age: 25 }
111+
*/
112+
export type Traits = object & JSONObject // intersection adds an index signature
113+
114+
/**
115+
* An object literal representing Segment event properties
116+
* - track: https://segment.com/docs/connections/spec/track/#properties
117+
* - page: https://segment.com/docs/connections/spec/page/#properties
118+
* - screen: https://segment.com/docs/connections/spec/screen/#properties
119+
* @example
120+
* { artistID: 2435325, songID: 13532532 }
121+
*/
122+
export type EventProperties = object & JSONObject // intersection adds an index signature
114123

115124
export interface SegmentEvent {
116125
messageId?: string

0 commit comments

Comments
 (0)