-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
noUnusedLocals: Don't count self-call in recursive function #16078
Comments
how far do we want to go with this? is a class that is only instantiated in an instance method the same? a var that is only referenced in its own intializer? etc.. |
It makes sense to disclude any use of a class inside itself, since the self-references won't be used unless the class is. But I don't think I would treat instantiation specially, since it's hard to tell when a reference to a class might instantiate it. class C {
static s() {
new C().m();
}
m() {
new C();
}
}
maybeThisInstantiatesIt(C);
function maybeThisInstantiatesIt(klass: any) {
klass.s();
} Without the A variable initialized to itself is an error anyway if you use |
On the other hand, the mere presence of a static property may be side-affecting in its initialization, so the following code, which marks function sideAffecting(): number {
console.log("called");
return 10;
}
function foo() {
class D {
static s: number = sideAffecting();
}
}
foo(); But perhaps this should be a separate issue. |
|
I agree with @andy-ms . This is an issue on checking recursive functions. We don't need to consider classes. @aozgaa In your case, |
TypeScript Version: nightly (2.4.0-dev.20170525)
Code
Expected behavior:
Function
f
is unused.Actual behavior:
No error.
(Ref: palantir/tslint#1937)
The text was updated successfully, but these errors were encountered: