I am working on a function that generates a POST request from class properties, but I have encountered an issue with data types.
Here's the code snippet:
public state: number;
updateField(field: string | number, name: string, team: boolean = true) {
this.http.post('/update_key', {
[path]: { [name]: field }
})
}
In this code snippet,
path
represents a firebase path such as/ipl_data/match_info/current_match
I invoke the function like this:
this.updateField(this.state, 'state', false);
However, the issue arises when the request body is created. The expected result should be:
{
"/ipl_data/match_info/current_match": {
"state":"3"
} ^------ Inconsistent datatype: expecting a number
}
Is there a solution to handle this problem?