namespace A {
interface A {} // error: shadowed name 'A'
let v = A; // namespace A
let t: A; // interface A
}
Error for shadowed name 'A'
Technically there's no shadowing, because both names can coexist in different domains.
Do we want to allow this at all? By default or with an option?
The implementation would not be too difficult.
eh, I guess you're right, we could make this change to be technically correct. I don't see this "shadowing" pattern being very valuable in practice so I would prefer it to be opt-in by default (keep the rule strict by default).
I just updated to tslint 5.6.0 from 4.0 - I've previously had 'shadowed variables' checks enabled however they're now failing for the following pattern of code:
constructor(private $i18next: ngI18Next.I18NextService,
private $scope: angular.IScope,
private $uibModal: angular.ui.bootstrap.IModalService,
private AuthenticationService: AuthenticationService)
The use of the type and parameter as the same name (AuthenticationService - this is angular 1.x code) cause the message "Shadowed name: 'AuthenticationService'"
I think it's the same issue as this bug? I tried adjusting the options for no-shadow-variable but adding "typeAlias": false && "typeParameter": false didn't seem to make any difference?
Is there a solution to this issue? Other than going back to 4.0?
@mahmoudm The quick fix is to disable checking of everything but parameters and variables to (almost) restore the behavior of 4.x
"no-shadowed-variable": [
true,
{
"class": false,
"enum": false,
"function": false,
"interface": false,
"namespace": false,
"typeAlias": false,
"typeParameter": false,
"import": false
}
]
Thanks @ajafff works like a charm!
The use of the type and parameter as the same name (AuthenticationService - this is angular 1.x code) cause the message "Shadowed name: 'AuthenticationService'"
I'd love to see this addressed too. let SomeModel: SomeModel or similar shouldn't fail. There's no shadowing or reader ambiguity, and it makes sense for the type and the variable to have the same name in some cases.
โ ๏ธ TSLint's time has come! โ ๏ธ
TSLint is no longer accepting most feature requests per #4534. See typescript-eslint.io for the new, shiny way to lint your TypeScript code with ESLint. โจ
It was a pleasure open sourcing with you all!
๐ค Beep boop! ๐ TSLint is deprecated ๐ _(#4534)_ and you should switch to typescript-eslint! ๐ค
๐ This issue is being locked to prevent further unnecessary discussions. Thank you! ๐
Most helpful comment
I just updated to tslint 5.6.0 from 4.0 - I've previously had 'shadowed variables' checks enabled however they're now failing for the following pattern of code:
The use of the type and parameter as the same name (AuthenticationService - this is angular 1.x code) cause the message "Shadowed name: 'AuthenticationService'"
I think it's the same issue as this bug? I tried adjusting the options for no-shadow-variable but adding
"typeAlias": false&&"typeParameter": falsedidn't seem to make any difference?