![](/img/trans.png)
[英]Typescript (React) function declaration correct but paramters show "any" type
[英]Type error in declaration part in typescript (Angular/React)
當我嘗試運行以下組件時,它在我的聲明中顯示類型問題
下面是我遇到的問題 Type '{ First: string[]; 第二個:字符串[]; 第三個:string[]; 四:string[]; }' 缺少類型 'any[]' 中的以下屬性:length、pop、push、concat 和 28 個其他屬性。 TS2740
接口標頭聲明我已經嘗試過標頭數據 any,String,Array 但它不起作用
interface headers {
First: any[],
Second: any[],
Third: any[],
Four:any[],
}
const 標頭數據聲明
const headers = {
First: [
'lara',
'dravid',
'sachin',
'Ganguly',
],
Second: [
'kohli',
'dhoni',
'smith',
'kane',
],
Third: [
'lee',
'mustaq',
'vaas',
'shane',
],
Four: [
'bumrah',
'starc',
'jadeja',
'shami',
],
};
Export state
export interface State {
headersList: Array<any>
}
主要組件類
export class MyComp extends React.PureComponent<Props, State> {
constructor(props) {
super(props);
this.state = {
headersList: headers,
};
this.state = {
headersList: [headers],
};
會解決問題
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.