角度 AOT 保护在参数未使用时抛出错误(声明"next"但从未使用)



我刚刚升级到 Angular 4.1.1据我了解,AOT 现在默认处于打开状态(这很棒(。

我有一个不使用下一个参数的警卫。

如果我尝试按原样运行代码,则会出现'next' is declared but never used. 错误。

如果我删除"下一个"参数,我会收到此错误: Class 'AuthGuard' incorrectly implements interface 'CanActivate'.

这是警卫的代码:

@Injectable()
export class AuthGuard implements CanActivate {
  constructor(private authService: AuthenticationService) {}
  canActivate(
    next: ActivatedRouteSnapshot,
    state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean {
      return this.authService.guardCheck(state.url);
    }
}

处理此错误的最佳方法是什么?

如果有人遇到此问题,只需删除"noUnusedParameters": true,来自 tsconfig.ts

最新更新