-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Leak of noImplicitAny
checking with private static property
#6415
Comments
@falsandtru with these issues you'll have to be specific about what the expected behavior is and what the current actual behavior is. Can you elaborate on that? |
Sorry, I updated the description. |
noImplicitAny
checkingnoImplicitAny
checking with private static property
So the reason we don't error on here with |
I know your idea. Private instance members in classes have inaccessibility. declare class C {
private implicitAnyTypeProperty; // not an error because this type is inaccessible
} but private static members are not. declare class C {
private static implicitAnyTypeProperty;
static inherited: typeof C.implicitAnyTypeProperty;
inherited: typeof C.implicitAnyTypeProperty;
}
var D: typeof C;
//class D extends C { }
var a = D.inherited; // should be an error because this variable accessed to implicitAny type
var b = new D().inherited; // same as above This accessibility seems not intended design because this accessibility of private static members escapes inaccessibility of private members (for instance). ImplicitAny type is visible from implementations. Indeed, |
This is a good point @falsandtru. I do not think we thought of that before. enabling no-implicit-any checks on these declarations would be a breaking change now. Given that this pattern is not common, I wounder if it is worth it though. |
The TypeScript type system policy is a balance, but no-implicit-any checks is probably not. It checks is desired to be perfect. I think that the next major version up to 2.0 is a good chance for breaking changes. If this pattern is not common as you say, this breaking change is easy. TypeScript can get more correct no-implicit-any checks easily. |
i meant the use of a static property as a target of a typeof expression to type something else. The private static property is a common pattern, and making this an error would break a lot of code. for instance all the .d.ts files that were generated by the compiler would fail this check. |
We'd like it to be an error for a non- |
Is this something that you still want? class A {
private test = 10;
}
type Test = A["test"] // ok
declare function fn<T extends A>(a: T): T["test"]; // Private or protected member 'test' cannot be accessed on a type parameter.(4105) And this makes sense because, in the generic context, this indexed access is deferred and this wouldn't be OK. The simple non-generic context works fine though. Should the same principle be applied to the |
Maybe the best version of the rule is that |
expected:
actual:
The text was updated successfully, but these errors were encountered: