I am attempting to compare the elements in one list (list A) with another list (list B), and if there is a match, I want to change a property/field of the corresponding items in list B to a boolean value.
Below is the code snippet:
export default defineComponent({
name: 'Users',
props: {
existingUsers : {
type: Array as PropType<Array<UserModel>>,
}
},
async setup(props) {
const allUsers = ref<Array<UserModel>>(await userService.list())
const userList = ref<Array<UserModel>>([{ id: 0, email: '', first_name: '', last_name: '', }])
function defineUsers(): Array<UserModel> {
if (props.existingUsers) {
const existingUsers = props.existingUsers;
userList.value = allUsers.value
.map((user: UserModel) => existingUsers
.forEach((us: UserModel) => (us.id === user.id) ? user.isSelected = true : user));
return userList.value;
} else {
userList.value = allUsers.value;
return userList.value;
}
}
defineUsers();
In summary, if no existing users are passed as props, then userList will be set to allUsers (which obtains data from an API through a GET request). If existing users are provided as props, then each user in allUsers that matches an entry in existingUsers should have its 'isSelected' value set to true.
The error I encountered regarding userList.value on line 3 within the function defineUsers is:
Type 'ComputedRef<void[]>' is missing the following properties from type '{ id: number; email: string; first_name: string; last_name: string; organization?: { id: number; company_name: string; address: string; postal_code: string; city: string; state: string; country: string; vat: string; fiscal_code?: string | undefined; codice_sdi?: string | undefined; registration_date?: string | undef...': length, pop, push, concat, and 28 more.Vetur(2740)
Any insights on how to resolve this issue?
Thank you very much.