简体   繁体   English

Typescript Object 的类型未知

[英]Typescript Object is of type unknown

How to define the data type of value in the nodejs function written in typescript, so that error of Object is of type unknow can be solved?如何在typescript编写的nodejs function中定义value的数据类型,从而解决Object类型为unknow的错误?

在此处输入图像描述

You need to implement type for value.您需要为值实现类型。 Try smth like this:像这样尝试:

type valueType = {
  id: string,
  field1: number,
  field2: string,
}

const obj = {
  a: {
    id: '12',
    field1: 1,
    field2: 'asdas',
  }
}

for (const [key, value] of Object.entries(obj)) {
  const typedValue: valueType = value;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何为 Typescript 中的未知 object 属性动态分配名称和类型 - How to dynamically assign a name and type to unknown object property in Typescript 错误 TS2571:对象在打字稿中属于“未知”类型 - error TS2571: Object is of type 'unknown' in typescript 在 Typescript 中,try...catch 错误 object 显示“对象类型为‘unknown’.ts(2571)” - in Typescript, try...catch error object shows "Object is of type 'unknown'.ts(2571)" TypeScript:当函数的返回类型未知时该怎么办 - TypeScript: what to do when return type of library function is unknown 打字稿错误:量角器中的“未知”类型不存在“清除”或“发送”属性 - Typescript error: Property 'clear' or 'send' does not exist on type 'unknown' in protractor API 在 Typescript 中接收到未知的正文或参数,如何检查类型 - API receiving unknown body or parameter in Typescript, how to check the type 用Mongoose引用具有未知模型类型的对象 - Referencing an object with an unknown model-type with Mongoose 类型“数组”的属性在领域对象服务器中具有未知的对象类型 - Property of type 'array' has unknown object type in realm object server 类型检查...... object 的 rest 字段与 Typescript - Type check … rest fields of an object with Typescript typescript 在类型'typeof object 上不存在 - typescript does not exist on type 'typeof object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM