ค้นหาเว็บไซต์

typescript - TypeError: พบ @@iterator ที่ไม่สามารถเรียกใช้งานได้


ฉันมีคลาสแบบสแตติกที่มีฟังก์ชันสแตติกบางตัวที่ห่อหุ้มฟังก์ชันบางตัวของ Application Insights ในโปรเจกต์ react-typescript

เมื่อแอปพลิเคชันโหลด ฟังก์ชันคงที่หนึ่งจะถูกเรียก ซึ่งจะเรียกฟังก์ชันคงที่อีกตัวหนึ่ง ก่อนที่ฟังก์ชันคงที่ตัวที่สองนั้นจะเริ่มทำงาน แอปพลิเคชันจะเกิดข้อผิดพลาด Uncaught (in promise) TypeError: Found non-callable @@iterator

// wrapper function 
public static TrackAndReturnException(
  errorMessage: string | Error,
  caller: string,
  severityLevel = SeverityLevel.Error,
  properties ? : any
): Error {
  // Error thrown here and TrackTrace is never entered
  this.TrackTrace(
    errorMessage.toString(),
    caller,
    severityLevel,
    ...properties
  )
}

// wrapper function
public static TrackTrace(
  message: string,
  caller: string,
  severityLevel = SeverityLevel.Verbose,
  properties ? : any
): void {

  // native function
  this.AppInsights.trackTrace({
    message: message,
    severityLevel: severityLevel,
    properties: {
      caller: caller,
      ...properties
    },
  })
}

อย่างไรก็ตาม หากใช้ฟังก์ชันของตัวเครื่อง (แทนที่จะใช้ตัวห่อ) ข้อผิดพลาดจะหายไป

// wrapper function 
public static TrackAndReturnException(
  errorMessage: string | Error,
  caller: string,
  severityLevel = SeverityLevel.Error,
  properties ? : any
): Error {
  // No error; TrackTrace (below) is not used
  this.AppInsights.trackTrace({
    message: errorMessage.toString(),
    severityLevel: severityLevel,
    properties: {
      caller: caller,
      ...properties
    },
  })
}

// wrapper function
public static TrackTrace(
  message: string,
  caller: string,
  severityLevel = SeverityLevel.Verbose,
  properties ? : any
): void {

  // native function
  this.AppInsights.trackTrace({
    message: message,
    severityLevel: severityLevel,
    properties: {
      caller: caller,
      ...properties
    },
  })
}

TrackAndReturnException ไม่ถูกเรียกโดยฟังก์ชัน ComponentDidMount แบบอะซิงโครนัส แต่ก็ไม่ได้อยู่ภายในพรอมิสที่ถูกส่งกลับเอง ฉันไม่เข้าใจความเชื่อมโยงตรงนี้ว่าทำไมข้อผิดพลาดนั้นถึงเกิดขึ้นตรงที่มันเกิด วิธีแก้ปัญหาทำได้ง่าย แต่ซ้ำซ้อน มีใครเคยเห็นเรื่องนี้มาก่อนหรือรู้ไหมว่าทำไมฉันถึงเจอข้อผิดพลาดนี้ตรงที่ฉันเจอ?