firebase / firebase-js-sdk

Firebase Javascript SDK
https://firebase.google.com/docs/web/setup
Other
4.76k stars 874 forks source link

Typings for Remote Config defaults (`defaultConfig`) are missing JSON values #6106

Open ceisele-r opened 2 years ago

ceisele-r commented 2 years ago

[REQUIRED] Describe your environment

[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:

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

google-oss-bot commented 2 years ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

jbalidiong commented 2 years ago

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.

sceee commented 2 years ago

@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.

hsubox76 commented 2 years ago

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.