Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript - Parameter 'u' implicitly has an 'any' type

I converted this code to the latest Angular 2. authentication.service.ts

What should the code look like?

app/auth/auth.service.ts(30,40): error TS7006: Parameter 'u' implicitly has an 'any' type.

// services/auth.service.ts
import {Injectable} from '@angular/core';
import {Router} from '@angular/router';

//http://4dev.tech/2016/03/login-screen-and-authentication-with-angular2/
//https://github.com/leonardohjines/angular2-login
export class User {
  constructor(
    public email: string,
    public password: string) { }
}

var users:any = [
  new User('[email protected]','adm9'),
  new User('[email protected]','a23')
];

@Injectable()
export class AuthenticationService {

  constructor(
    private _router: Router){}

  logout() {
    localStorage.removeItem("user");
    this._router.navigate(['Login']);
  }

  login(user:any){
    var authenticatedUser = users.find(u => u.email === user.email);
    if (authenticatedUser){
      localStorage.setItem("user", authenticatedUser);
      this._router.navigate(['Home']);      
      return true;
    }
    return false;

  }

   checkCredentials( ){
    if (localStorage.getItem("user") === null){
        this._router.navigate(['Login']);
    }
  } 
}
like image 732
Tampa Avatar asked Jul 05 '16 07:07

Tampa


1 Answers

Consider using (u: any) => ...

like image 67
Cengkuru Michael Avatar answered Sep 23 '22 01:09

Cengkuru Michael