Typescript - tslint is inappropriate for 'else' (single line)

I am using the TSLint extension for VS Code. I got a bunch of warnings [tslint] misplaced 'else' (one-line). For example, in the example code below, linter underlines another word and gives the same warning:

The code:

if (user.isAdmin) {
    this.uiRouter.stateService.go('app.admin');
}
else {
    this.sharedVariables.user = user;
    this.navigateByUserType(user);
}

What is the problem with this code?

+4
source share
1 answer

From tslint single line rule documentation

Rule: Single Line

The specified markers are required to be on the same line as the expression preceding them.

tslint enabled one-line , check-else. tslint else, , . else , if, tslint.

if (user.isAdmin) {
    this.uiRouter.stateService.go('app.admin');
} else {
    this.sharedVariables.user = user;
    this.navigateByUserType(user);
}
+9

Source: https://habr.com/ru/post/1672530/


All Articles