Reputation: 3301
I'm using library which has a method loadUserInfo(): KeycloakPromise<{}, void>
. I'm calling it using `this.getKeycloakInstance().loadUserInfo().success(data => {
this.user.id = (data).sub;
I checked using debugger that this data
object has field sub which I want to assign to this.user.id
I cannot do so becasue I'm getting compilation error: TS2339: Property 'sub' does not exist on type '{}'.
I cannot change return type of method loadUserInfo() as it's external lib which I have to use. Can I get this sub
property somehow without error?
Upvotes: 0
Views: 96
Reputation:
You can with variable['sub']
, or by typing your variable as any
.
this.getKeycloakInstance()
.loadUserInfo()
.success(data => this.user.id = data.sub); // error
this.getKeycloakInstance()
.loadUserInfo()
.success(data => this.user.id = data['sub']); // no error
this.getKeycloakInstance()
.loadUserInfo()
.success(data => this.user.id = (data as any).sub); // no error
this.getKeycloakInstance()
.loadUserInfo()
.success((data: any) => this.user.id = data.sub); // no error
Upvotes: 3