9
votes

Something simple that will cause this to happen.

let _tick = 0;
this.app.ticker.add( () => {
   moveSprites(dots);
   _tick += .2;
   return;
});

Tslint options are set to the following:

"rules": {
  "object-literal-sort-keys": false,
  "no-unused-variable": [true, {"ignore-pattern": "^_"}]
}

From searching I thought that rule would resolve and allow it to be ignored but nope.

One solution was to write it like this. It will pass but it will then complain about the tick += .2 being assigned but never used. Plus, this changes the behavior.

this.app.ticker.add( (tick = 0) => {
   moveSprites(dots);
   tick += .2;
   return;
});

Then finally I found // @ts-ignore and that worked... I'm new to typescript and I could see this being a problem in instances were you just need to keep up a variables state; only ever setting it. I also see some conventions to _var name as protected class fields but also for these instances as well? What is the right way? I like the benefits of TS, but being new I'm spending a lot of time appeasing the ts linter.

1
I'm new to typescript and I could see this being a problem in instances were you just need to keep up a variables state; only ever setting it. If you have a variable which is never read from the variable is useless, just remove it.tkausl
Why keep the state if you're not doing anything with the state? The moment you do something with the tick variable, typescript will stop complaining.Evert
Oh... Right.. it's late and I'm reading lint errors vs reading the code. I should have caught that. Like you said once I'm doing something all is good...JustDave

1 Answers

20
votes

You can disable the check setting noUnusedLocals to false in your tsconfig.json file.

Take a look at the compiler options for more info.