I have the following TypeScript interface, which is used to map data from a HTTP response:
interface Person {
firstName: string;
lastName: string;
active: boolean;
}
Here's the sample response:
{
firstName: 'John',
lastName: 'Brown',
active: 1;
}
Here's the logic used to store the response into a local variable:
const person: Person = response;
The following provides the same result:
const person = response as Person;
Based on the logic described above, the person object results in the following:
{
firstName: 'John',
lastName: 'Brown',
active: 1;
}
The problem is the the 'active' property is expected to be a boolean, true or false, not an integer.
Any ideas how to address this issue?
Note that checking the value and converting it is not a viable option because the response could be an array of a hundred objects and I would not want to traverse them.
Also, the backend can not be changed to pass true or false in the response. The response must contain a 1 or 0.