I'm facing a challenge in converting an object retrieved from the server to a TypeScript class I've created.
While my TypeScript object has identical properties to the one returned by the server, the difference lies in the casing of the property names. The properties in my TypeScript class are camel cased, whereas those in the server's object are title cased. This mismatch causes issues when trying to access properties like userModel.isActive in my TypeScript code. Below is the API call return statement made by my provider.
return this.httpClient.post<UserModel>(url, { params: queryParams });
I have attempted:
this.userProvider.getUser(request).subscribe(modelReturnedFromApi => {
Object.assign(this.myTypeScriptModel, modelReturnedFromApi)
this.myTypeScriptModel = modelReturnedFromApi
this.myTypeScriptModel = JSON.stringify(modelReturnedFromApi)
})
Could someone provide guidance on how to resolve this issue? Thank you in advance.
Update: It seems that there isn't a built-in solution for what I require, so I've decided to align the property names in my TypeScript class with those returned from the server. Appreciate all the support provided.