Making Sense of 'No Shadowed Variable' tslint Warning

后端 未结 7 1569
隐瞒了意图╮
隐瞒了意图╮ 2020-12-10 09:58

I have a function that checks for the current stage in a sequential stream, based on a particular discipline that is passed in, and, according to that value, assigns the nex

7条回答
  •  醉酒成梦
    2020-12-10 10:44

    The linter complains because you are redefining the same variable multiple times. Thus replacing the ones in the closure containing it.

    Instead of redeclaring it just use it:

    private getNextStageStep(currentDisciplineSelected) {
        let nextStageStep = '';
            if (this.stageForDiscipline(this.currentDisciplineSelected) === 'step 1') {
                 nextStageStep = 'step 2';
            } else if (this.stageForDiscipline(this.currentDisciplineSelected) === 'step 2') {
                 nextStageStep = 'step 3';
            } else if (this.stageForDiscipline(this.currentDisciplineSelected) === 'step 3') {
                 nextStageStep = 'step 4';
            } else if (this.stageForDiscipline(this.currentDisciplineSelected) === 'step 4') {
                 nextStageStep = 'step 5';
            } else if (this.stageForDiscipline(this.currentDisciplineSelected) === 'step 5') {
                 nextStageStep = 'step 6';
        }
        return nextStageStep;
    }
    

提交回复
热议问题