Skip to content

Commit 137556a

Browse files
committed
simplify
1 parent 7b07406 commit 137556a

File tree

7 files changed

+40
-68
lines changed

7 files changed

+40
-68
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 & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ 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)
3737
// we may want to remove this...
3838
[key: string]: any
@@ -142,7 +142,7 @@ export interface CoreExtraContext {
142142
* but also associate information from a previous identify call.
143143
* You should fill this object the same way you would fill traits in an identify call.
144144
*/
145-
traits?: CoreUserTraits
145+
traits?: Traits
146146

147147
/**
148148
* 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 +187,7 @@ export interface CoreSegmentEvent {
187187

188188
properties?: EventProperties
189189

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

192192
integrations?: Integrations
193193
context?: CoreExtraContext
@@ -257,30 +257,30 @@ type PhoneNumber = string | number // TODO: the docs say this can only be a stri
257257
* This interface represents reserved traits that Segment has standardized.
258258
* @link https://segment.com/docs/connections/spec/group/#traits
259259
*/
260-
type BaseCoreGroupTraits = DeepNullable<{
260+
type BaseGroupTraits = DeepNullable<{
261261
/**
262262
* Street address of a group.
263263
*/
264-
address?: BaseCoreUserTraits['address']
264+
address?: BaseUserTraits['address']
265265

266266
/**
267267
* URL to an avatar image for the group.
268268
*/
269-
avatar?: BaseCoreUserTraits['avatar']
269+
avatar?: BaseUserTraits['avatar']
270270

271271
/**
272272
* Date the group's account was first created. Segment recommends ISO-8601 date strings.
273273
*/
274-
createdAt?: BaseCoreUserTraits['createdAt']
274+
createdAt?: BaseUserTraits['createdAt']
275275

276276
/**
277277
* Description of a group
278278
*/
279-
description?: BaseCoreUserTraits['description']
279+
description?: BaseUserTraits['description']
280280
/**
281281
* Email address of group.
282282
*/
283-
email?: BaseCoreUserTraits['email']
283+
email?: BaseUserTraits['email']
284284
/**
285285
* Number of employees of a group, typically used for companies.
286286
*/
@@ -289,40 +289,40 @@ type BaseCoreGroupTraits = DeepNullable<{
289289
/**
290290
* Unique ID in your database for a group.
291291
*/
292-
id?: BaseCoreUserTraits['id']
292+
id?: BaseUserTraits['id']
293293

294294
/**
295295
* Industry a group is part of.
296296
*/
297-
industry?: BaseCoreUserTraits['industry']
297+
industry?: BaseUserTraits['industry']
298298

299299
/**
300300
* Name of a group.
301301
*/
302-
name?: BaseCoreUserTraits['name']
302+
name?: BaseUserTraits['name']
303303

304304
/**
305305
* Phone number of a group
306306
*/
307-
phone?: BaseCoreUserTraits['phone']
307+
phone?: BaseUserTraits['phone']
308308

309309
/**
310310
* Website of a group.
311311
*/
312-
website?: BaseCoreUserTraits['website']
312+
website?: BaseUserTraits['website']
313313

314314
/**
315315
* Plan that a group is in.
316316
*/
317-
plan?: BaseCoreUserTraits['plan']
317+
plan?: BaseUserTraits['plan']
318318
}>
319319

320320
/**
321321
* Traits are pieces of information you know about a user.
322322
* This interface represents reserved traits that Segment has standardized.
323323
* @link https://segment.com/docs/connections/spec/identify/#traits
324324
*/
325-
type BaseCoreUserTraits = DeepNullable<{
325+
type BaseUserTraits = DeepNullable<{
326326
/**
327327
* Unique ID in your database for a user
328328
*/
@@ -400,9 +400,9 @@ type BaseCoreUserTraits = DeepNullable<{
400400
company?: {
401401
name?: string
402402
id?: DbId
403-
industry?: BaseCoreUserTraits['industry']
403+
industry?: BaseUserTraits['industry']
404404
employee_count?: number
405-
plan?: BaseCoreUserTraits['plan']
405+
plan?: BaseUserTraits['plan']
406406
}
407407

408408
/**
@@ -438,7 +438,7 @@ type BaseCoreUserTraits = DeepNullable<{
438438
* This interface represents reserved traits that Segment has standardized.
439439
* @link https://segment.com/docs/connections/spec/group/#traits
440440
*/
441-
export type CoreGroupTraits = BaseCoreGroupTraits & {
441+
export type GroupTraits = BaseGroupTraits & {
442442
[customTrait: string]: any
443443
}
444444

@@ -447,8 +447,11 @@ export type CoreGroupTraits = BaseCoreGroupTraits & {
447447
* This interface represents reserved traits that Segment has standardized.
448448
* @link https://segment.com/docs/connections/spec/identify/#traits
449449
*/
450-
export type CoreUserTraits = BaseCoreUserTraits & {
450+
export type UserTraits = BaseUserTraits & {
451451
[customTrait: string]: any
452452
}
453453

454-
export type CoreTraits = CoreUserTraits & CoreGroupTraits
454+
/**
455+
* Traits are pieces of information you know about a user or group.
456+
*/
457+
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, GroupTraits, Plugin, UserTraits } 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)