我有這段代碼:const sectionInstance: FieldValues = sectionInstances[i]for (const field in sectionInstance) { console.log(sectionInstance[field])}field這里當然是一個字符串。這是 的類型定義FieldValues:export interface FieldValues = { [key: string]: FieldValue;}我仍然收到此錯誤:元素隱式具有“任何”類型,因為類型“字符串”的表達式不能用于索引類型“FieldValues”。在類型“FieldValues”上找不到參數類型為“string”的索引簽名。Vetur(7053)我沒有為 聲明類型為“string”的索引簽名interface FieldValues嗎?為什么會出現此錯誤?
接口上“字符串”類型的索引簽名無法識別(打字稿)
白衣染霜花
2022-12-18 16:06:43