Auth0-spa-js: Auth0Client.getUser() should return Promise<Auth0UserProfile> not Promise<any>

Created on 15 Nov 2019  路  2Comments  路  Source: auth0/auth0-spa-js

Describe the problem you'd like to have solved

Auth0Client.getUser() return Promise<any>, which provides no useful type information about what is returned. The properties of the user profile are known, and they should be specified. Otherwise, the value of using TypeScript is diminished.

Describe the ideal solution

Auth0Client.getUser() should return Promise<Auth0UserProfile> not Promise<any>.

Alternatives and current work-arounds

Currently casting the returned user to Auth0UserProfile, which I found in @types/auth0-js.

Most helpful comment

Thanks @stevehobbsdev

I realize that several of the properties of the user profile would have to have any types, but typing the top-level properties would still be extremely helpful.

All 2 comments

One of the reasons we don't type this is because the user profile can be pretty fluid; there might be other things in there (adding using the Rules feature, for example).

However, I agree that we could use generics here to configure what the return type is if you know what you're expecting back in terms of ID token claims. I will add that to our backlog for investigation - thanks!

Thanks @stevehobbsdev

I realize that several of the properties of the user profile would have to have any types, but typing the top-level properties would still be extremely helpful.

Was this page helpful?
0 / 5 - 0 ratings