@@ -12,8 +12,10 @@ import {
1212 EventProperties ,
1313 SegmentEvent ,
1414 Traits ,
15+ GroupTraits ,
16+ IdentifyTraits ,
1517} from '../events'
16- import { ID , User } from '../user'
18+ import { Group , ID , User } from '../user'
1719
1820/**
1921 * Helper for the track method
@@ -105,8 +107,10 @@ export function resolvePageArguments(
105107/**
106108 * Helper for group, identify methods
107109 */
108- export const resolveUserArguments = ( user : User ) : ResolveUser => {
109- return ( ...args ) : ReturnType < ResolveUser > => {
110+ export const resolveIdentifyOrGroupArguments = < T extends Traits > (
111+ user : User | Group
112+ ) : ResolveIdentifyOrGroup < T > => {
113+ return ( ...args ) : ReturnType < ResolveIdentifyOrGroup < T > > => {
110114 let id : string | ID | null = null
111115 id = args . find ( isString ) ?? args . find ( isNumber ) ?. toString ( ) ?? user . id ( )
112116
@@ -117,7 +121,7 @@ export const resolveUserArguments = (user: User): ResolveUser => {
117121 return isPlainObject ( obj ) || obj === null
118122 } ) as Array < Traits | null >
119123
120- const traits = ( objects [ 0 ] ?? { } ) as Traits
124+ const traits = ( objects [ 0 ] ?? { } ) as T
121125 const opts = ( objects [ 1 ] ?? { } ) as Options
122126
123127 const resolvedCallback = args . find ( isFunction ) as Callback | undefined
@@ -146,14 +150,15 @@ export function resolveAliasArguments(
146150 return [ aliasTo , aliasFrom , opts , resolvedCallback ]
147151}
148152
149- type ResolveUser = (
153+ type ResolveIdentifyOrGroup < T extends Traits > = (
150154 id ?: ID | object ,
151- traits ?: Traits | Callback | null ,
155+ traits ?: T | Callback | null ,
152156 options ?: Options | Callback ,
153157 callback ?: Callback
154- ) => [ ID , Traits , Options , Callback | undefined ]
158+ ) => [ ID , T , Options , Callback | undefined ]
155159
156- export type UserParams = Parameters < ResolveUser >
160+ export type IdentifyParams = Parameters < ResolveIdentifyOrGroup < IdentifyTraits > >
161+ export type GroupParams = Parameters < ResolveIdentifyOrGroup < GroupTraits > >
157162export type EventParams = Parameters < typeof resolveArguments >
158163export type PageParams = Parameters < typeof resolvePageArguments >
159164export type AliasParams = Parameters < typeof resolveAliasArguments >
0 commit comments