Skip to content

Commit b39ba9e

Browse files
authored
Fixed the wrong type of method params
当前 index.d.ts 中定义的 properties 参数类型时 Map,实际中如果按 Map 传过去的话原生接收不到传过去的值,而按 Object 传过去的话原生是能拿到这个值的。 以 Android 为例,原生方法 Java 的 ReadableMap 参数类型对应到 JavaScript 的类型时 Object。 参考链接:https://reactnative.dev/docs/native-modules-android#argument-types
1 parent 5bbab60 commit b39ba9e

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

index.d.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
declare type PropertiesType = string | number | boolean | Array<string>;
22

3+
declare type PropertiesObjectType = { [key: string]: PropertiesType }
4+
35
declare module 'sensorsdata-analytics-react-native'{
46

57
/**
@@ -18,24 +20,23 @@ declare module 'sensorsdata-analytics-react-native'{
1820
* 设置用户属性
1921
*
2022
* @param profile 用户属性
21-
2223
*/
23-
export function profileSet(profile: Map<string,PropertiesType>): void
24+
export function profileSet(profile: PropertiesObjectType): void
2425

2526
/**
2627
* 记录初次设定的属性
2728
*
2829
* @param profile 用户属性
2930
*/
30-
export function profileSetOnce(profile: Map<string,PropertiesType>): void
31+
export function profileSetOnce(profile: PropertiesObjectType): void
3132

3233
/**
3334
* 追踪事件
3435
*
3536
* @param event 事件名称
3637
* @param properties 事件属性
3738
*/
38-
export function track(event: string, properties?: Map<string,PropertiesType> | null): void;
39+
export function track(event: string, properties?: PropertiesObjectType | null): void;
3940

4041
/**
4142
* 事件开始
@@ -50,7 +51,7 @@ declare module 'sensorsdata-analytics-react-native'{
5051
* @param event 事件名称
5152
* @param properties 事件属性
5253
*/
53-
export function trackTimerEnd(event: string, properties?: Map<string,PropertiesType> | null): void;
54+
export function trackTimerEnd(event: string, properties?: PropertiesObjectType | null): void;
5455

5556
/**
5657
* 清除所有事件计时器
@@ -63,15 +64,15 @@ declare module 'sensorsdata-analytics-react-native'{
6364
* @param eventName 事件名称
6465
* @param properties 事件属性
6566
*/
66-
export function trackInstallation(eventName: string, properties?: Map<string,PropertiesType> | null): void;
67+
export function trackInstallation(eventName: string, properties?: PropertiesObjectType | null): void;
6768

6869
/**
6970
* 切换页面的时候调用,用于记录 $AppViewScreen 事件..
7071
*
7172
* @param url 页面 url
7273
* @param properties 事件属性
7374
*/
74-
export function trackViewScreen(url: string, properties?: Map<string,PropertiesType> | null): void;
75+
export function trackViewScreen(url: string, properties?: PropertiesObjectType | null): void;
7576

7677
/**
7778
* 给一个数值类型的 Profile 增加一个数值. 只能对数值型属性进行操作,若该属性
@@ -117,7 +118,7 @@ declare module 'sensorsdata-analytics-react-native'{
117118
*
118119
* @param properties 公共属性
119120
*/
120-
export function registerSuperProperties(properties:Map<string,PropertiesType>): void;
121+
export function registerSuperProperties(properties: PropertiesObjectType): void;
121122

122123
/**
123124
* 删除某个公共属性
@@ -142,7 +143,6 @@ declare module 'sensorsdata-analytics-react-native'{
142143
export function deleteAll(): void;
143144

144145
/**
145-
146146
/**
147147
* 替换“匿名 ID”
148148
*
@@ -203,7 +203,7 @@ declare module 'sensorsdata-analytics-react-native'{
203203
* @param itemId item ID
204204
* @param properties item 相关属性
205205
*/
206-
export function itemSet(itemType: string, itemId: string, properties: Map<string,PropertiesType> | null): void;
206+
export function itemSet(itemType: string, itemId: string, properties: PropertiesObjectType | null): void;
207207

208208
/**
209209
* 删除 item
@@ -216,12 +216,12 @@ declare module 'sensorsdata-analytics-react-native'{
216216
/**
217217
* 获取事件公共属性
218218
*/
219-
export function getSuperPropertiesPromise(): Promise<Map<string,PropertiesType>>;
219+
export function getSuperPropertiesPromise(): Promise<PropertiesObjectType>;
220220

221221
/**
222222
* 返回预置属性
223223
*/
224-
export function getPresetPropertiesPromise(): Promise<Map<string,PropertiesType>>;
224+
export function getPresetPropertiesPromise(): Promise<PropertiesObjectType>;
225225

226226
/**
227227
* 获取当前用户的 loginId 若调用前未调用 {@link #login(String)} 设置用户的 loginId,会返回 null
@@ -271,7 +271,7 @@ declare module 'sensorsdata-analytics-react-native'{
271271
*
272272
* @param properties 渠道追踪事件的属性
273273
*/
274-
export function trackAppInstall(properties: Map<string,PropertiesType> | null)
274+
export function trackAppInstall(properties: PropertiesObjectType | null)
275275

276276
/************** Android only start *****************/
277277
/**
@@ -316,4 +316,3 @@ declare module 'sensorsdata-analytics-react-native'{
316316

317317
/************** Android only end *****************/
318318
}
319-

0 commit comments

Comments
 (0)