Angular 7: 使用 Typescript 接口进行解构,出现错误

Angular 7: destructuring with Typescript interface, getting errors

我有这样的界面:

像这样的组件:

但是我收到这个错误:

我怎样才能解构我的价值观,让 Typescript 满意?

在你的本地声明中,你可以试试:

@Input() accounts: Accounts;
myAccountsList: Array<AccountList>;
authorizedAccountsList: Array<AccountList>;

我想是因为你把myAccountsListauthorizedAccountsList的变量声明为AccountList类型,但是在接口中你定义为Array<AccountList>。根据哪种类型是正确的,您需要更改:

如果类型是AccountList,在界面上修改:

export interface Accounts {
    authorizedAccountsList: AccountList;
    myAccountsList: AccountList;
}

如果类型是Array<AccountList>,改变变量的声明:

@Input() accounts: Accounts;
myAccountsList: Array<AccountList>;
authorizedAccountsList: Array<AccountList>;