Typings for Remote Config defaults (`defaultConfig`) are missing JSON values
[REQUIRED] Describe your environment
- Operating System version: Windows 11
- Browser version: Chrome 100
- Firebase SDK version: 8 / 9
- Firebase Product: remote config
[REQUIRED] Describe the problem
Via Firebase Console, we can set a JSON value for a remote config entry.
But in a (typescript) application, there is no way to set a default JSON value as the typings for defaultConfig only allow a default config value to be either string, number or boolean.
The issue seems to be in these two places:
- https://github.com/firebase/firebase-js-sdk/blob/1c37b5e965978d796c46ff6b9f52051cf6070751/packages/remote-config-types/index.d.ts#L27
- https://github.com/firebase/firebase-js-sdk/blob/1c37b5e965978d796c46ff6b9f52051cf6070751/packages/firebase/compat/index.d.ts#L1899
Steps to reproduce:
Try to set the remote config default value to a JSON value via
remoteConfig.defaultConfig = {
"myfeatureflag": {
foo: "bar"
},
}
This creates the following Typescript error:
Type '{ [x: string]: { foo: string; }; }' is not assignable to type '{ [key: string]: string | number | boolean; }'.
'string' index signatures are incompatible.
Type '{ foo: string; }' is not assignable to type 'string | number | boolean'.ts(2322)
Relevant Code:
See above
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
Hi @ceisele-r, thanks for the report. I was able to reproduce the behavior now. Let me check what we can do for this issue or bring someone here that can provide more context about it. I’ll update this thread if I have any information to share.
@jbalidiong thanks. After working a bit more with it, I am actually unsure whether JSON values defined in the dashboard end up in the web app as string value (JSON.stringify'ed) and that's the reason why only string | number | boolean is allowed...
Would be cool if someone could clarify this.
Looking at the code, it seems it's stored locally as whatever type of value you put in (number, string, boolean, JSON object), however if you try to get the value using getValue(), it will be returned as a string using String() which, if the value is an object, will be [object Object].
It seems reasonable to add a getJSON() method in the same vein as getNumber(), getBoolean(), and we can make this a feature request.
Hello, I have made the changes to add support for getJson method.
Should i go ahead and create a pull request?