我是 Typescript 的新手,我必須為以下道具型別構建一個界面:
const myProps = [
{
name: 'name1',
on: true,
children: [
{ name: 'test1', href: '#' },
{ name: 'test2', href: '#' },
{ name: 'test3', href: '#' }
]
},
{
name: 'name2',
on: false,
children: [
{ name: 'test1', href: '#' },
{ name: 'test2', href: '#' },
{ name: 'test3', href: '#' },
{ name: 'test4', href: '#' },
{ name: 'test5', href: '#' }
]
},
{
name: 'name3',
on: false,
children: [{ name: 'test1', href: '#' }]
}
];
我想為它創建一個用于 React Typescript 應用程式的界面。
這是目前的界面:
export interface IChildren {
name: string,
href: string
}
export interface IMyProps {
name: string,
on: boolean,
children: IChildren,
}
它不起作用,我猜它應該有一些陣列。有什么建議?
uj5u.com熱心網友回復:
你可以這樣試試
export interface CommonProps {
name: string;
href: string;
}
export interface MyProps {
name: string;
on: boolean;
children: Array<CommonProps>;
}
另請注意,資料介面不應以命名約定開頭
"I"具有方法宣告的介面應該具有"I"類似IMethodService
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/355934.html
標籤:javascript 反应 打字稿 反应打字稿
