【发布时间】:2021-05-14 10:12:45
【问题描述】:
我有以下代码:
axios.get<Response>(url)
.then(response => {
console.log(response.data);
}).catch(error => {
// handle error
console.log(error);
});
JSON 响应包含我无法在 TypeScript 中表达的字段:
{
"field:Type": "foo"
}
like: name:Type 包含 string - 在我的例子中是 "foo"
如何在Response 接口中映射此类字段以便以后使用?
interface Response {
myMappedField: string;
}
【问题讨论】:
标签: json typescript axios mapping