How to get RemoteConfig defaultValue inside firebase function?

泪湿孤枕 提交于 2020-08-10 19:46:32

问题


I am writing a firebase function.

And in there, I need a default value.

And since I set up a Remote Config in Firebase, I try to use it inside my firebase function (to have one source of truth as for the default-values)

Using the following code to retrieve a remoteConfig-parameter, how can you convert it to a typescript number ?

const remoteConfigTemplate = await admin.remoteConfig().getTemplate();

const defaultVal = remoteConfigTemplate.parameters["video_max_duration"].defaultValue

const actualValue = defaultVal.value;

const finalValue: number = Number(actualValue);

In the code above, I see that defaultVal is of type RemoteConfigParameterValue?. But how do I convert it to a number in typescript ??

I tried to cast the defaultValue but this does not work...

const defaultVal = remoteConfigTemplate.parameters["video_max_duration"].defaultValue as ExplicitParameterValue

The error is Cannot find name 'ExplicitParameterValue'.ts(2304)

What is still wrong ?

Is there another way of getting a Firebase Remote Config defaultValue into a firebase function ?

来源:https://stackoverflow.com/questions/63307572/how-to-get-remoteconfig-defaultvalue-inside-firebase-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!