react-sdk icon indicating copy to clipboard operation
react-sdk copied to clipboard

[OptimizelyProvider UserAttributes Type Definition mismatch] The type definition for the user attributes does not match the documentation and is limiting types allowed

Open victor-optimizely opened this issue 1 year ago • 2 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

SDK Version

3.1.0

Current Behavior

The new package has defined the UserAttributeValue to be a limited set of types which contradicts the documentation stating it supports any type. What's happening now is that if you have a custom type being set as an attribute you will receive a typescript error because the type is not supported.

Expected Behavior

The user prop in the OptimizelyProvider should allow any type definition as stated in the documentation instead of the currently defined type:

export type UserAttributeValue = string | number | boolean | null;

⬇️

export type UserAttributeValue = any;

or simply:

export type UserAttributes = {
    [name: string]: UserAttributeValue;
};

⬇️

export type UserAttributes = {
    [name: string]: any;
};

Steps To Reproduce

  • setup a project with the lastest react sdk
  • In the OptimizelyProvider's user prop, add a custom attribute that has a json value:
            <OptimizelyProvider
                optimizely={optimizelyInstance}
                user={{
                    id: profile?.id || null,
                    attributes: {
                        my_custom_attribute: { name: "something", type: "something" },
                    }
                }}
            >
                {children}
            </OptimizelyProvider>

Note the TS error: image

React Framework

create-react-app

Browsers impacted

No response

Link

No response

Logs

No response

Severity

Blocking development

Workaround/Solution

Solution listed above. Workaround might be to ts-ignore and ensure the attribute is being used.

Recent Change

No response

Conflicts

No response

victor-optimizely avatar Apr 24 '24 13:04 victor-optimizely

It looks like the underlying definition is in the @optrimizely/sdk package so I've duplicated this issue there. Since it would still take an update here not sure if you want to keep it open to follow up (I would).

victor-optimizely avatar Apr 24 '24 13:04 victor-optimizely

@victor-optimizely, is this ticket still valid?

junaed-optimizely avatar Aug 27 '24 13:08 junaed-optimizely

I am closing this due to inactivity. Please feel free to reopen it if required!

junaed-optimizely avatar Nov 07 '24 11:11 junaed-optimizely