En mi aplicación angular, tengo una función que básicamente devuelve un objeto.
private getTypeAndLocation() { const type = sessionStorage.getItem('type'); const location = sessionStorage.getItem('location'); return {type, location}; } Ahora estoy llamando a esta función desde ngOnint así:
({this.MyObjectVariable.type, this.MyObjectVariable.location} = this.getWorkClearanceTypeAndLocation()); Pero desafortunadamente no funciona. Estoy recibiendo este error:
Property 'this' does not exist on type '{ type: string | null; location: string | null; }'.
Es posible que getTypeAndLocation devuelva undefined si el tipo y la ubicación no están configurados.
En ese caso, ¿cómo puedo hacer la desestructuración del objeto?