Skip to content

Commit fe72fc5

Browse files
committed
simplify
1 parent 7b07406 commit fe72fc5

File tree

7 files changed

+40
-69
lines changed

7 files changed

+40
-69
lines changed

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

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
CoreTraits,
32
CoreOptions,
43
CoreSegmentEvent,
54
Callback,
@@ -11,27 +10,14 @@ import {
1110
JSONValue,
1211
JSONPrimitive,
1312
JSONObject,
14-
CoreGroupTraits,
15-
CoreUserTraits,
13+
GroupTraits,
14+
UserTraits,
15+
Traits,
1616
} from '@segment/analytics-core'
1717

1818
export interface Options extends CoreOptions {}
1919

20-
export interface Traits extends CoreTraits {}
21-
22-
/**
23-
* Traits are pieces of information you know about a group.
24-
* This interface represents reserved traits that Segment has standardized.
25-
* @link https://segment.com/docs/connections/spec/group/#traits
26-
*/
27-
export interface GroupTraits extends CoreGroupTraits {}
28-
29-
/**
30-
* Traits are pieces of information you know about a user.
31-
* This interface represents reserved traits that Segment has standardized.
32-
* @link https://segment.com/docs/connections/spec/identify/#traits
33-
*/
34-
export interface UserTraits extends CoreUserTraits {}
20+
export type { GroupTraits, UserTraits, Traits }
3521

3622
export type EventProperties = Record<string, any>
3723

packages/core-integration-tests/src/typedef-tests.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CoreTraits, CoreExtraContext } from '@segment/analytics-core'
1+
import { Traits, CoreExtraContext } from '@segment/analytics-core'
22

33
class TestClass {
44
name = 'hello'
@@ -8,8 +8,8 @@ class TestClass {
88
}
99

1010
export default {
11-
'CoreTraits test': () => {
12-
let traits: CoreTraits = {}
11+
'Traits test': () => {
12+
let traits: Traits = {}
1313

1414
// should accept a class
1515
traits = new TestClass()

packages/core/src/events/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import {
77
CoreSegmentEvent,
88
CoreOptions,
99
CoreExtraContext,
10-
CoreUserTraits,
11-
CoreGroupTraits,
10+
UserTraits,
11+
GroupTraits,
1212
} from './interfaces'
1313
import { pickBy } from '../utils/pick'
1414
import { validateEvent } from '../validation/assertions'
@@ -104,7 +104,7 @@ export class EventFactory {
104104

105105
identify(
106106
userId: ID,
107-
traits?: CoreUserTraits,
107+
traits?: UserTraits,
108108
options?: CoreOptions,
109109
globalIntegrations?: Integrations
110110
): CoreSegmentEvent {
@@ -120,7 +120,7 @@ export class EventFactory {
120120

121121
group(
122122
groupId: ID,
123-
traits?: CoreGroupTraits,
123+
traits?: GroupTraits,
124124
options?: CoreOptions,
125125
globalIntegrations?: Integrations
126126
): CoreSegmentEvent {

packages/core/src/events/interfaces.ts

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ export interface CoreOptions {
3232
context?: CoreExtraContext
3333
anonymousId?: string
3434
userId?: string
35-
traits?: CoreUserTraits
35+
traits?: Traits
3636
// ugh, this is ugly, but we allow literally any property to be passed to options (which get spread onto the event)
37-
// we may want to remove this...
3837
[key: string]: any
3938
}
4039

@@ -142,7 +141,7 @@ export interface CoreExtraContext {
142141
* but also associate information from a previous identify call.
143142
* You should fill this object the same way you would fill traits in an identify call.
144143
*/
145-
traits?: CoreUserTraits
144+
traits?: Traits
146145

147146
/**
148147
* Dictionary of information about the campaign that resulted in the API call, containing name, source, medium, term, content, and any other custom UTM parameter.
@@ -187,7 +186,7 @@ export interface CoreSegmentEvent {
187186

188187
properties?: EventProperties
189188

190-
traits?: CoreTraits // Traits is only defined in 'identify' and 'group', even if it can be passed in other calls.
189+
traits?: Traits // Traits is only defined in 'identify' and 'group', even if it can be passed in other calls.
191190

192191
integrations?: Integrations
193192
context?: CoreExtraContext
@@ -257,30 +256,30 @@ type PhoneNumber = string | number // TODO: the docs say this can only be a stri
257256
* This interface represents reserved traits that Segment has standardized.
258257
* @link https://segment.com/docs/connections/spec/group/#traits
259258
*/
260-
type BaseCoreGroupTraits = DeepNullable<{
259+
type BaseGroupTraits = DeepNullable<{
261260
/**
262261
* Street address of a group.
263262
*/
264-
address?: BaseCoreUserTraits['address']
263+
address?: BaseUserTraits['address']
265264

266265
/**
267266
* URL to an avatar image for the group.
268267
*/
269-
avatar?: BaseCoreUserTraits['avatar']
268+
avatar?: BaseUserTraits['avatar']
270269

271270
/**
272271
* Date the group's account was first created. Segment recommends ISO-8601 date strings.
273272
*/
274-
createdAt?: BaseCoreUserTraits['createdAt']
273+
createdAt?: BaseUserTraits['createdAt']
275274

276275
/**
277276
* Description of a group
278277
*/
279-
description?: BaseCoreUserTraits['description']
278+
description?: BaseUserTraits['description']
280279
/**
281280
* Email address of group.
282281
*/
283-
email?: BaseCoreUserTraits['email']
282+
email?: BaseUserTraits['email']
284283
/**
285284
* Number of employees of a group, typically used for companies.
286285
*/
@@ -289,40 +288,40 @@ type BaseCoreGroupTraits = DeepNullable<{
289288
/**
290289
* Unique ID in your database for a group.
291290
*/
292-
id?: BaseCoreUserTraits['id']
291+
id?: BaseUserTraits['id']
293292

294293
/**
295294
* Industry a group is part of.
296295
*/
297-
industry?: BaseCoreUserTraits['industry']
296+
industry?: BaseUserTraits['industry']
298297

299298
/**
300299
* Name of a group.
301300
*/
302-
name?: BaseCoreUserTraits['name']
301+
name?: BaseUserTraits['name']
303302

304303
/**
305304
* Phone number of a group
306305
*/
307-
phone?: BaseCoreUserTraits['phone']
306+
phone?: BaseUserTraits['phone']
308307

309308
/**
310309
* Website of a group.
311310
*/
312-
website?: BaseCoreUserTraits['website']
311+
website?: BaseUserTraits['website']
313312

314313
/**
315314
* Plan that a group is in.
316315
*/
317-
plan?: BaseCoreUserTraits['plan']
316+
plan?: BaseUserTraits['plan']
318317
}>
319318

320319
/**
321320
* Traits are pieces of information you know about a user.
322321
* This interface represents reserved traits that Segment has standardized.
323322
* @link https://segment.com/docs/connections/spec/identify/#traits
324323
*/
325-
type BaseCoreUserTraits = DeepNullable<{
324+
type BaseUserTraits = DeepNullable<{
326325
/**
327326
* Unique ID in your database for a user
328327
*/
@@ -400,9 +399,9 @@ type BaseCoreUserTraits = DeepNullable<{
400399
company?: {
401400
name?: string
402401
id?: DbId
403-
industry?: BaseCoreUserTraits['industry']
402+
industry?: BaseUserTraits['industry']
404403
employee_count?: number
405-
plan?: BaseCoreUserTraits['plan']
404+
plan?: BaseUserTraits['plan']
406405
}
407406

408407
/**
@@ -438,7 +437,7 @@ type BaseCoreUserTraits = DeepNullable<{
438437
* This interface represents reserved traits that Segment has standardized.
439438
* @link https://segment.com/docs/connections/spec/group/#traits
440439
*/
441-
export type CoreGroupTraits = BaseCoreGroupTraits & {
440+
export type GroupTraits = BaseGroupTraits & {
442441
[customTrait: string]: any
443442
}
444443

@@ -447,8 +446,11 @@ export type CoreGroupTraits = BaseCoreGroupTraits & {
447446
* This interface represents reserved traits that Segment has standardized.
448447
* @link https://segment.com/docs/connections/spec/identify/#traits
449448
*/
450-
export type CoreUserTraits = BaseCoreUserTraits & {
449+
export type UserTraits = BaseUserTraits & {
451450
[customTrait: string]: any
452451
}
453452

454-
export type CoreTraits = CoreUserTraits & CoreGroupTraits
453+
/**
454+
* Traits are pieces of information you know about a user or group.
455+
*/
456+
export type Traits = UserTraits | GroupTraits

packages/node/src/__tests__/typedef-tests.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { Analytics, Context, Plugin, GroupTraits } from '../'
2-
import { Traits, UserTraits } from '../app/types'
1+
import { Analytics, Context, Plugin, UserTraits, GroupTraits } from '../'
32

43
/**
54
* These are general typescript definition tests;
@@ -56,6 +55,5 @@ export default {
5655
'traits should be exported': () => {
5756
console.log({} as GroupTraits)
5857
console.log({} as UserTraits)
59-
console.log({} as Traits)
6058
},
6159
}

packages/node/src/app/types/params.ts

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,13 @@
11
import type {
2-
CoreTraits,
3-
CoreGroupTraits,
4-
CoreUserTraits,
2+
GroupTraits,
3+
UserTraits,
54
CoreExtraContext,
65
EventProperties,
76
Integrations,
87
Timestamp,
98
} from '@segment/analytics-core'
109

11-
export interface Traits extends CoreTraits {}
12-
13-
/**
14-
* Traits are pieces of information you know about a group.
15-
* This interface represents reserved traits that Segment has standardized.
16-
* @link https://segment.com/docs/connections/spec/group/#traits
17-
*/
18-
export interface GroupTraits extends CoreGroupTraits {}
19-
20-
/**
21-
* Traits are pieces of information you know about a user.
22-
* This interface represents reserved traits that Segment has standardized.
23-
* @link https://segment.com/docs/connections/spec/identify/#traits
24-
*/
25-
export interface UserTraits extends CoreUserTraits {}
10+
export type { GroupTraits, UserTraits }
2611

2712
/**
2813
* A dictionary of extra context to attach to the call.

packages/node/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export { Analytics } from './app/analytics-node'
22
export { Context } from './app/context'
3-
export { ExtraContext, Plugin, UserTraits, GroupTraits } from './app/types'
3+
export { Plugin, GroupTraits, UserTraits } from './app/types'
44
export type { AnalyticsSettings } from './app/settings'
55

66
// export Analytics as both a named export and a default export (for backwards-compat. reasons)

0 commit comments

Comments
 (0)