【发布时间】:2020-02-27 03:04:08
【问题描述】:
我正在尝试将通知优先级设置为HIGH,如文档here 和定义的特定参数here 中所述。但是,当我在云函数中设置此属性时,尝试部署时出现以下错误:
src/index.ts:107:35 - error TS2345: Argument of type '{ tokens: string[]; notification: { title: string; body: any; }; data: { title: any; subtitle: any; body: any; id: any; }; android: { notification: { icon: string; channel_id: string; tag: any; }; priority: string; }; }' is not assignable to parameter of type 'MulticastMessage'.
The types of 'android.priority' are incompatible between these types.
Type 'string' is not assignable to type '"normal" | "high" | undefined'.
107 admin.messaging().sendMulticast(message)
~~~~~~~
我明白这意味着我不应该输入字符串。但根据文档,这是预期的类型。不仅如此,我对引号'"normal | "high" | undefined' 所指的类型感到非常困惑。那是什么类型的?
这是正在设置的完整消息容器:
const message = {
tokens: tokens,
notification: {
title: snapshot.data().sender_username + " - " + snapshot.data().group_name,
body: snapshot.data().content
},
data: {
title: snapshot.data().group_name,
subtitle: snapshot.data().sender_username,
body: snapshot.data().content,
id: message_topic
},
android: {
notification: {
icon: 'add_circle_outline',
channel_id: 'exampleChannelId',
tag: message_topic
},
priority: "high" // <-- This is where the error is thrown
}
};
【问题讨论】:
标签: node.js firebase-cloud-messaging firebase-admin