属性'x'已声明但从未使用过.误报

JGF*_*FMK 3 typescript tslint

在我的Ionic 3项目中,我似乎得到了很多误报:

这是正常的吗?

12:27:29] tslint:src/pages/tabs/tabs.ts,line:28属性'navParams'已声明但从未使用过.

  L27:  constructor(
  L28:    private navParams: NavParams,
  L29:    @Inject(forwardRef(() => AuthService ))
Run Code Online (Sandbox Code Playgroud)

[12:27:29] tslint:src/pages/tabs/tabs.ts,line:30属性'authService'已声明但从未使用过.

  L29:    @Inject(forwardRef(() => AuthService ))
  L30:    private authService:AuthService
  L31:  ) {
Run Code Online (Sandbox Code Playgroud)

然而,这是代码:

export class TabsPage {
  ...
  mySelectedIndex: number;
  loggedIn:boolean;
  constructor(
    private navParams: NavParams,
    @Inject(forwardRef(() => AuthService ))
    private authService:AuthService
  ) {
    console.log('TabsPage constructor: navParams.data: ', navParams.data);
    this.loggedIn = authService.authenticated(RootPage.LAUNCHPAD.toString());
    this.mySelectedIndex = navParams.data.tabIndex || 0;
    console.log('Tabs pages: selectedIndex: ' + this.mySelectedIndex);
    console.log('Tabs pages: loggedIn: ' + this.loggedIn);
  }

  isLoggedIn():boolean {
    return this.loggedIn;
  }
}
Run Code Online (Sandbox Code Playgroud)

raw*_*med 8

如果在typescript文件之外使用声明的变量,则需要删除修饰符.尝试删除私人.这将解决这个问题.


Tit*_*mir 5

由于您使用私有修饰符声明参数,因此它将成为类字段,实际上该类字段从未使用过.如果只使用构造函数中的参数,请删除修饰符.