You will have to parse the XML and turn it into an Object.
The response object is currently of type string. With the as syntax you tell typescript to treat it like another type - it does not change the type of the object itself.
On how to convert an XML entity to a JavaScript Object look here.
Once you have a JavaScript Object you can use the as syntax to tell TypeScript to treat it as a Request.
An example of this (using xml-js):
import {xml2js} from 'xml-js'
// or with require:
// const xml2js = require('xml-js').xml2js;
enum status {
Pending = 1,
Rejected = 5,
Validated = 6
}
interface Request { // Using interface instead of type
totalInDays: number;
status: status; // I think you had a mistake here in your question - should be of type 'status' not 'string'
}
const response = '<ns1:Request>
<ns1:totalInDays>0.5</ns1:totalInDays>
<ns1:status>1</ns1:durationInDays>
<ns1:startDate>22/07/2019</ns1:startDate>
<ns1:endDate>22/07/2019</ns1:endDate>
</ns1:Request>'
const object:Response = xml2js(response) as Response; // as Response might not be needed depending on the libraries typings, if there are any