Строка типа не может быть присвоена ‘never’ Angular

#angular #typescript

#angular #typescript

Вопрос:

Получение error TS2322: Type 'string | undefined' is not assignable to type 'never' сообщения о том, что я пытался назначить 4 поля для этих 4 полей, отображалась ошибка TS2322

  1. ‘ObjectId’: current.ObjectId
  2. ‘LocationName’: loc.LocationName
  3. ‘attributeName’: attr.attributeName,
  4. ‘AttributeValue’: attr.AttributeValue
 parseResponse(objects: empDetails): any {
    return objects?.empList?.reduce((data, current: empList) => {
      current?.locationDetails?.forEach(loc=> {
        loc?.attributeDetails?.forEach(attr => {
          data.push({
 'objectId': current.objectId, 'locationName': loc.locationName, 'attributeName': attr.attributeName, 'attributeValue': attr.attributeValue
          });
        });
      });
      return data;
    }, []);
  }

 

Комментарии:

1. Каков ваш тип empDetails и empList как он выглядит?

Ответ №1:

определение данных :

 const data = [];
data.push({
 'objectId': current.objectId, 'locationName': loc.locationName, 'attributeName': attr.attributeName, 'attributeValue': attr.attributeValue
          });
        });
      });