I have defined the structure of MenuItem
as follows in order to parse the response from the server side rest api:
type MenuItem = {
id: number;
name: string;
path: string;
tree_id_path: string;
children: MenuItem[];
};
The server side is returning more than 4 fields, but I only want the MenuItem
to contain those 4 fields. How can I achieve this? Currently, I am using the 'as' keyword to cast the response to a list of MenuItem
.
export async function roleMenuTree(options?: { [key: string]: any }) {
let response = await request<API.ApiResponse>('/manage/permission/role/v1/role/menu', {
method: 'POST',
body: JSON.stringify({}),
...(options || {}),
});
let dataList = response.result as API.MenuItem[];
return dataList;
}