簡體   English   中英

如何將此 JS 修復為 TS?

[英]How to fix this JS into TS?

{ for (var i: number = 0; i < selectedProfile.length; i++) {
    if (i % 3 === 2) {
      <div className="sliderContainer">
    }
  } 
}

算術操作數的類型必須為“any”、“number”、“bigint”或枚舉 type.ts(2356)。 參數初始化器僅允許在 function 或構造函數實現中使用。

我該如何解決這個問題? 第一行發生錯誤?

該數組中 object 的接口定義如下:

export interface ILinkedInProfile { 
  postContent: string; 
  postUrl: string; 
  profileUrl: string; 
  action: string; 
  imgUrl: string; 
  likeCount: number; 
  companyName: string; 
}

Object 類型上不存在屬性“長度”。

您可以嘗試Object.keys(selectedProfile).length來獲取它的長度

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM