Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

218
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!