[英]Property 'length' does not exists on type 'ITravel'. TS2339
我無法弄清楚如何在 json object 我從 axios.get 響應中獲得數組。 我不斷得到**屬性'長度'在類型''上不存在。 TS2339 錯誤。 如何擺脫這個錯誤? json 合約如下。 我跳過了一些代碼,只放了相關部分。
{
"someStuff":{
"items":[
{
"id":1
},
{
"id":2
}
]
}
}
旅游.tsx
export interface ISomeStuff{
}
export interface IItems{
id:number;
}
export interface ITravel extends ISomeInterface{
items: IItems[];
}
路線.tsx
import React from 'react';
import FormLabel from 'react-bootstrap/FormLabel';
import { ITravel } from './ITravel.tsx';
type Props = {
iTravel: ITravel;
}
const Route = (props: Props) => {
const { items } = props.iTravel;
return(
<FormLabel>
<strong>{items.length}</strong>
</FormLabel>
);
}
只能看到您粘貼的代碼,我的兩個想法 go 到:
我發現了這個問題。 基本上,每當我在編譯 Route.tsx 之前對其進行更改時,我都需要“保存”ITravel.tsx。 不確定這是否與vscode有關。 我是新來的反應。 在視覺工作室中,我不記得每次更改后都這樣做。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.