Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSONObject type used for metadata doesn't accept typescript interface #857

Open
markusenglund opened this issue Jun 13, 2024 · 3 comments
Open

Comments

@markusenglund
Copy link

The following code causes this ts error:

Argument of type 'UserMeta' is not assignable to parameter of type 'JSONObject'. Index signature for type 'string' is missing in type 'UserMeta'

        import UserMetadata from 'supertokens-node/recipe/usermetadata';

        // ...later
        interface UserMeta {
            foo: string;
        }

        const userMetadata: UserMeta = {
            foo: 'bar',
        };

        await UserMetadata.updateUserMetadata(
            response.user.id,
            userMetadata, // Argument of type 'UserMeta' is not assignable to parameter of type 'JSONObject'. Index signature for type 'string' is missing in type 'UserMeta'.
        );

Switching from interface to a type works ok:

        type UserMeta = {
            foo: string;
        };

I haven't made the effort to figure out why, but if seems like incorrect behavior.

@rishabhpoddar
Copy link
Contributor

We generally prefer using type instead of interface as types are more flexible. I don't think this is an issue with our SDK though.

@markusenglund
Copy link
Author

Your preferences might not be shared by the consumers of your library. In the project I'm working on, we need to use a class as the type of the metadata due to the framework we're using. Type-casting to appease the ts compiler is totally fine for us, I'm just letting you know that this is an annoyance.

@rishabhpoddar
Copy link
Contributor

Fair enough. We will see what we can do about this if more people face this same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants