node.js - 检查一些数据以包含某些接口的字段(Typescript)
问题描述
我想找到 API (nodejs) 的解决方案。当我收到任何数据的请求时,我想为特定模型(接口、类型等)处理这些数据。
这个回购完美地描述了我的情况。如何在不更改 typescript-compiler 的情况下获得相同的结果?
我尝试使用反射,但我对 typesctipt 的了解还不够。
我的示例代码逻辑:
type Person = {
name: string,
age: number,
address: {
city: string,
street: string,
house: number,
},
};
const input_data = {
name: 'John',
age: 23,
address: {
city: 'NY',
street: "Grand Street",
house: 15,
},
}
function check (data: any, InterfaceObjTitle: string): boolean {
// *getting type InterfaceObjTitle (current case person) from the variable*
// * cycle for checking fields of InterfaceObjTitle within data
}
check(input_data, 'Person ');
解决方案
推荐阅读
- cluster-analysis - OpenLayers Cluster Source 不返回 (source.getSource()) 的确切原始给定 Source
- javascript - 如何在第二个 SwitchMap 中返回 2 个响应对象并在订阅方法中使用
- python - Selenium - 如何填充值并单击按钮
- java - 如何在 JAVA 中使用 Regex 为句子中的每个单词设置最大限制
- vue.js - 无法将 VueApexCharts 组件正确包含到应用程序中
- ios - 代码签名“ResearchKit.framework”失败
- go - 有没有办法在golang的gorm db中命名外键
- r - R:删除一列是另一列的子字符串的行
- javascript - 谷歌图表,定义变量和arrayToDataTable
- c# - InvalidOperationException:传递到 ViewDataDictionary 的模型项的类型为“System.Collections.Generics - 如何解决此问题?