supertokens-node
supertokens-node copied to clipboard
JSONObject type used for metadata doesn't accept typescript interface
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.
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.
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.
Fair enough. We will see what we can do about this if more people face this same issue.