Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit fe7933c

Browse files
committed
fix(core): fix TypeScript typings
Fixes segmentio#11
1 parent 9978cd7 commit fe7933c

File tree

3 files changed

+44
-68
lines changed

3 files changed

+44
-68
lines changed

packages/core/src/bridge.ts

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,47 @@
11
import { NativeModules } from 'react-native'
22

3-
import bridge = NativeModules.RNAnalytics
3+
export interface Configuration {
4+
writeKey: string
5+
recordScreenViews: boolean
6+
trackAppLifecycleEvents: boolean
7+
trackAttributionData: boolean
8+
debug: boolean
9+
flushAt: number
10+
11+
android: {
12+
flushInterval?: number
13+
collectDeviceId: boolean
14+
}
15+
ios: {
16+
trackAdvertising: boolean
17+
trackDeepLinks: boolean
18+
}
19+
}
20+
21+
export type JsonValue = boolean | number | string | null | JsonList | JsonMap
22+
export interface JsonMap {
23+
[key: string]: JsonValue
24+
[index: number]: JsonValue
25+
}
26+
export interface JsonList extends Array<JsonValue> {}
27+
28+
export interface Bridge {
29+
setup(configuration: Configuration): Promise<void>
30+
track(event: string, properties: JsonMap, context: JsonMap): Promise<void>
31+
identify(user: string, traits: JsonMap, context: JsonMap): Promise<void>
32+
screen(name: string, properties: JsonMap, context: JsonMap): Promise<void>
33+
group(groupId: string, traits: JsonMap, context: JsonMap): Promise<void>
34+
alias(alias: string, context: JsonMap): Promise<void>
35+
reset(): Promise<void>
36+
flush(): Promise<void>
37+
enable(): Promise<void>
38+
disable(): Promise<void>
39+
}
40+
41+
const bridge: Bridge = NativeModules.RNAnalytics
442

543
if (!bridge) {
644
throw new Error('Failed to load Analytics native module.')
745
}
846

947
export default bridge
10-
export type JsonMap = NativeModules.RNAnalytics.JsonMap
11-
export type Bridge = typeof bridge

packages/core/src/configuration.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import { Analytics } from './analytics'
2-
import Bridge from './bridge'
2+
import { Configuration } from './bridge'
33

44
const defaults = {
55
android: ({
66
collectDeviceId = true,
77
flushInterval
8-
}: Partial<Bridge.Configuration['android']>) => ({
8+
}: Partial<Configuration['android']>) => ({
99
collectDeviceId,
1010
flushInterval
1111
}),
1212
ios: ({
1313
trackAdvertising = false,
1414
trackDeepLinks = false
15-
}: Partial<Bridge.Configuration['ios']>) => ({
15+
}: Partial<Configuration['ios']>) => ({
1616
trackAdvertising,
1717
trackDeepLinks
1818
})
@@ -31,7 +31,7 @@ export const configure = async (
3131
ios = {},
3232
android = {}
3333
}: Analytics.Configuration
34-
): Promise<Bridge.Configuration> => {
34+
): Promise<Configuration> => {
3535
await Promise.all(
3636
using.map(
3737
async integration =>

packages/core/src/modules.d.ts

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,2 @@
11
declare module '*.json'
2-
declare module 'react-native' {
3-
export namespace NativeModules.RNAnalytics {
4-
export interface Configuration {
5-
writeKey: string
6-
recordScreenViews: boolean
7-
trackAppLifecycleEvents: boolean
8-
trackAttributionData: boolean
9-
debug: boolean
10-
flushAt: number
11-
12-
android: {
13-
flushInterval?: number
14-
collectDeviceId: boolean
15-
}
16-
ios: {
17-
trackAdvertising: boolean
18-
trackDeepLinks: boolean
19-
}
20-
}
21-
22-
export type JsonValue =
23-
| boolean
24-
| number
25-
| string
26-
| null
27-
| JsonList
28-
| JsonMap
29-
export interface JsonMap {
30-
[key: string]: JsonValue
31-
[index: number]: JsonValue
32-
}
33-
export interface JsonList extends Array<JsonValue> {}
34-
35-
export function setup(configuration: Configuration): Promise<void>
36-
export function track(
37-
event: string,
38-
properties: JsonMap,
39-
context: JsonMap
40-
): Promise<void>
41-
export function identify(
42-
user: string,
43-
traits: JsonMap,
44-
context: JsonMap
45-
): Promise<void>
46-
export function screen(
47-
name: string,
48-
properties: JsonMap,
49-
context: JsonMap
50-
): Promise<void>
51-
export function group(
52-
groupId: string,
53-
traits: JsonMap,
54-
context: JsonMap
55-
): Promise<void>
56-
export function alias(alias: string, context: JsonMap): Promise<void>
57-
export function reset(): Promise<void>
58-
export function flush(): Promise<void>
59-
export function enable(): Promise<void>
60-
export function disable(): Promise<void>
61-
}
62-
}
2+
declare module 'react-native'

0 commit comments

Comments
 (0)