I am making an API call with Axios which returns JSON. The API returns CUSIP as type String, however, I would like to receive it as type Number. I created an interface which has the typescript type as number however when I get the variable, it is still treated as a String.
API Call and some logic:
const axios = require('axios');
import { General } from './json-objects-new';
module.exports = {
makeApiCall : function(ticker:string) {
axios.get(`${API_ENDPOINT}${ticker}?api_token=${API_KEY}`)
.then(function (response) {
// handle success
return response.data;
})
.catch(function (error) {
// handle error
console.log(error);
})
.then(data => {
let gen : General = data.General;
let num = gen.CUSIP + 1337
console.log(num);
});
}
}
interface called General where I cast CUSIP to number:
export interface General {
ISIN: string;
CUSIP: number;
}
The problem: instead of printing [CUSIP + 1337] as [2 + 1337 = 1339], it is printing [21337]. Would love some help thanks. I really dont want to have to cast everything manually in a constructor.