【发布时间】:2017-12-04 19:16:39
【问题描述】:
我有一个函数可以根据传入的特定学科检查顺序流中的当前阶段,并根据该值在我的 Angular 2 应用程序中分配下一个值。它看起来像这样:
private getNextStageStep(currentDisciplineSelected) {
const nextStageStep = '';
if (this.stageForDiscipline(this.currentDisciplineSelected) === 'step 1') {
const nextStageStep = 'step 2';
} else if (this.stageForDiscipline(this.currentDisciplineSelected) === 'step 2') {
const nextStageStep = 'step 3';
} else if (this.stageForDiscipline(this.currentDisciplineSelected) === 'step 3') {
const nextStageStep = 'step 4';
} else if (this.stageForDiscipline(this.currentDisciplineSelected) === 'step 4') {
const nextStageStep = 'step 5';
} else if (this.stageForDiscipline(this.currentDisciplineSelected) === 'step 5') {
const nextStageStep = 'step 6';
}
return nextStageStep;
}
我在这里所做的是返回 nextStageStep 的值,因为这是我将传递的值,以便正确的阶段步骤发生。
现在,我的 tslint 用警告 no shadowed variables 在每个出现的 nextStageStep 变量下划线。如果我删除了我初始化为空字符串的行,警告就会消失,但随后我会收到错误,Cannot find nextStageStep 会出现在我的返回语句中。
原始阴影变量警告有什么问题,是否有替代方法来编写,和/或在这种情况下我应该简单地忽略 tslint 警告吗?
【问题讨论】:
标签: javascript angular typescript tslint