Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

215
Vistas
Element implicitly has an 'any' type because expression of type '"status"' can't be used to index type 'Object'

Unable to index "res" with a string. I've tried other fixes i found but the context that it is used here in my code it does not recognise the object being defined earlier.

full error : "Element implicitly has an 'any' type because expression of type '"status"' can't be used to index type 'Object'. Property 'status' does not exist on type 'Object'.ts(7053)"

error here:

if(res['status'] === 'success')

full function:

export class LoginComponent implements OnInit {
    public user : User;
    
    
    constructor(private loginService: LoginService, private router: Router) {
        this.user = new User();
    }
    
    validateLogin() {
        if(this.user.username && this.user.password) {
            this.loginService.validateLogin(this.user).subscribe(res => {
                console.log('result is ', res);
                if(res['status'] === 'success') {
                    this.router.navigate(['/home']);
                } else {
                    alert('Wrong username password');
                }
            }, error => {
                console.log('error is ', error);
            });
        } else {
            alert('enter user name and password');
        }
    }
    
    ngOnInit(): void {
    }
    
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

you can try to note typescript that res is just a type, that can have status field, it may help

 if((res as {[key: string]: any})['status'] === 'success') {
    this.router.navigate(['/home']);
 } else {
    alert('Wrong username password');
 }

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda